dynamic click event

  • Thread starter samuelberthelot
  • Start date
S

samuelberthelot

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
 
J

Jessica Parker

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?
 
S

samuelberthelot

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 :
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top