fire an image button click event using javascript

G

Guest

..Hi all,

I want to catch an 'enter' keypress event on a web form and submit the form
as if a button had been clicked rather than the default post back behaviour.
I know the following javascript can be placed in the body tag to do this.

onkeydown="if(event.keyCode ==
13){document.getElementById('iBtnSubmit').onClick();

This will work fine if 'iBtnSubmit' is an input type of 'Button' but the
problem I am having is that the button in question is an image button. This
is rendered by the server as an input type of 'image' which does not have a
click method. Does anyone have any idea of how I can recreate this behaviour
for an imagebutton?

Thanks, Andy
 
G

Guest

Found a solution to this if anyone is interested. Instead of trying to fire a
click event set the focus on to the image button. This will then fire the
click event when the postback takes place. Again place this in the opening
<body> tag.

onkeydown="if((event.which ? event.which : event.keyCode) ==
13){document.getElementById('iBtnSubmit').focus();"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top