dynamic click event

Discussion in 'Javascript' started by samuelberthelot@googlemail.com, Jun 5, 2006.

  1. Guest

    Hi,
    I've got 3 textboxes and 3 buttons on my form.
    When I press enter in the first textbox, I'd like to have a click
    performed on the first button.
    Same thing for the other 2.

    I have a function that is called OnKeyPress event of my textboxes.
    2 issues:
    - How can I find out which textbox called the function ?
    - How can I perform a click on a button (the appropriate one) from the
    code ?

    thank you
    , Jun 5, 2006
    #1
    1. Advertising

  2. wrote:
    > Hi,
    > I've got 3 textboxes and 3 buttons on my form.
    > When I press enter in the first textbox, I'd like to have a click
    > performed on the first button.
    > Same thing for the other 2.
    >
    > I have a function that is called OnKeyPress event of my textboxes.
    > 2 issues:
    > - How can I find out which textbox called the function ?
    > - How can I perform a click on a button (the appropriate one) from the
    > code ?
    >
    > thank you


    I'm a bit new to javascript, but couldn't you pass the name of the
    textbox to the function? That would tell you which one, right?
    Jessica Parker, Jun 5, 2006
    #2
    1. Advertising

  3. Guest

    Yeah I've done that :

    function fct(evt, obj)
    {
    evt = (evt)? evt : event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if(charCode == 13)
    {
    if (obj.name == 'TextBox2')
    {
    alert('TextBox2');
    document.getElementById("Button2").submit();
    }
    else if (obj.name == 'TextBox3')
    {
    alert('TextBox3');
    document.getElementById("Button3").submit();
    }

    return false;
    }
    else
    return true;
    }

    Only problem is that it always triggerred a click on Button2, althoug
    if I'm in TextBox3 the code goes in the correct if (it shows 'TextBox3'
    in the alert popup).
    What am I missing ?
    Jessica Parker a écrit :

    > wrote:
    > > Hi,
    > > I've got 3 textboxes and 3 buttons on my form.
    > > When I press enter in the first textbox, I'd like to have a click
    > > performed on the first button.
    > > Same thing for the other 2.
    > >
    > > I have a function that is called OnKeyPress event of my textboxes.
    > > 2 issues:
    > > - How can I find out which textbox called the function ?
    > > - How can I perform a click on a button (the appropriate one) from the
    > > code ?
    > >
    > > thank you

    >
    > I'm a bit new to javascript, but couldn't you pass the name of the
    > textbox to the function? That would tell you which one, right?
    , Jun 5, 2006
    #3
    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:
    821
    Purvi T
    Oct 19, 2004
  2. mike parr
    Replies:
    1
    Views:
    459
    Marina
    May 20, 2004
  3. Chu
    Replies:
    2
    Views:
    895
    Winista
    Apr 10, 2006
  4. Amy
    Replies:
    0
    Views:
    961
  5. Max2006
    Replies:
    2
    Views:
    1,554
    Walter Wang [MSFT]
    Sep 19, 2007
Loading...

Share This Page