472,146 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

fire an image button click event using javascript

..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
Nov 19 '05 #1
1 10725
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(); "

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by ron | last post: by
4 posts views Thread by Mark Lingen | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.