Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simulate click on button 2

Status
Not open for further replies.

Pattycake245

Programmer
Oct 31, 2003
497
CA
I have a form with a textbox and a button on the bottom. What I have set up currently is if a value is entered in the text box and the user clicks the button it calls another page. How do I simulate it so that if the user just wants to press enter after entering something in the text box it will automatically act as though the button was pressed? I should also mention that I already have an onSubmit on the form which I do not want to fire until after the user edist information on the next page.

I hope I have explained this well enough.

Tim
 
What you can do is to setup event that will be fired when you leave the text box and set focus on the button. When the button is set focused, when you press enter, it will submit the form.

Code:
<form name="form1" method="post" action="next.asp">
   <input type="text" name "txt1" onBlur="document.form1.btnSubmit.focus()">
   <input type="button" name="btnSubmit" onClick="function()">
</form>
 
<input type="text" onkeypress="if(event.keyCode==13){buttonFunction()}">

Or

<input type="text" onkeypress="if(event.keyCode==13){document.formName.ButtonName.click()}">


Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Oh, I should've probably added "return false" to keep it from submitting the form.

Code:
<input type="text" onkeypress="if(event.keyCode==13){buttonFunction();return false}">

Or

Code:
<input type="text" onkeypress="if(event.keyCode==13){document.formName.ButtonName.click();return false}">

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Thanks to both of you. I ended up using adam0101's second solution and it works perfect. Amazing how simple the solution seems. I was close numerous times but couldn't get it. I guess I just need more practice.

thanks again,

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top