fire an image button click event using javascript

Discussion in 'ASP .Net' started by =?Utf-8?B?QW5keSBSb3Nl?=, Jun 30, 2005.

  1. ..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
    =?Utf-8?B?QW5keSBSb3Nl?=, Jun 30, 2005
    #1
    1. Advertising

  2. 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();"
    =?Utf-8?B?QW5keSBSb3Nl?=, Jun 30, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    830
    Purvi T
    Oct 19, 2004
  2. Amy
    Replies:
    0
    Views:
    976
  3. Nathan Sokalski
    Replies:
    0
    Views:
    1,059
    Nathan Sokalski
    Jan 15, 2009
  4. MU
    Replies:
    0
    Views:
    557
  5. Andy B.
    Replies:
    0
    Views:
    877
    Andy B.
    Nov 25, 2009
Loading...

Share This Page