Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > dynamic click event

Reply
Thread Tools

dynamic click event

 
 
samuelberthelot@googlemail.com
Guest
Posts: n/a
 
      06-05-2006
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

 
Reply With Quote
 
 
 
 
Jessica Parker
Guest
Posts: n/a
 
      06-05-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) 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?

 
Reply With Quote
 
 
 
 
samuelberthelot@googlemail.com
Guest
Posts: n/a
 
      06-05-2006
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 :

> (E-Mail Removed) 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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When user press F5 after a button click event, the click event fires again! Max2006 ASP .Net 2 09-19-2007 05:37 AM
Wire up a click event within another click event doesn't work... Chu ASP .Net 2 04-10-2006 10:43 PM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM



Advertisments