Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi frnds,

on my webpage i have a html image (with Print Image) this is used to print the records,
This is working fine.

My requirement is when i press ENTER button this Print image should clicked.

Please help, Thanks.
Posted
Comments
Gihan Liyanage 12-Aug-14 6:58am    
Did you try with Java Script ?

(document).keypress(function(e) {
if(e.which == 13) {
alert(You pressed enter!);
}
});

make sure you include jquery library in head section of your page
 
Share this answer
 
I guess you mean something like the below javascript example.
This will trigger the PrintImage click event everytime you press the Enter key.
JavaScript
function keyPressed(key)
{
  if (e.keyCode == '13')
  {
    $('#PrintImageID').click()
  }
}

if ($.browser.mozilla) {
    $(document).keypress (keyPressed);
} else {
    $(document).keydown (keyPressed);
}
 
Share this answer
 
C#
$('#signinpanel').keypress(function (e) {
               if (e.keyCode == '13') {
                  // your code
               }
           });
 
Share this answer
 
You can handle that using jQuery or JavaScript code which ever suits your document requirement. I would try to be short, so I will use jQuery.

JavaScript
// upon key down
$('body').keydown(function(e) {
    // get the key code, 13 is for enter
    if(e.keyCode == 13) {
       // trigger click event to the img
       $('img').trigger('click');
    }
});


This would do it, it would check for the keydown event of the body element. And if the key pressed was Enter key, then it will trigger click event on the image element.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900