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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oN ENTER 2

Status
Not open for further replies.

100dtl

Programmer
Aug 18, 2003
313
GB
Can anyone tell me how I submit a form on pressing enter
 
Not really what i wanted. when i press enter I want the form to submit? I see there is some bits but I'm not really a javascript person
 
mmmmmh, how about ASP? not ASPX ..

:-o
 
If you have all the fields in a form then pressing ENTER on any of those fields should make the submit.

________
George, M
 
Well it does'nt work, I have 2 fields usernmae password, on pressing enter it does'nt submit the form
 
Place this code between the head tags of your page, it will submit the first form on the page on pressing enter.
Code:
<script type=&quot;text/javascript&quot;>
<!--
window.onkeypress=checkKeyPressed;

function checkKeyPressed() {
if (event.keyCode==13){  
  document.forms[0].submit();
 }
}
//-->
<script>

Hope this helps

Simon
 
Do I call anywhere for checkKeyPressed>? it still does'nt work
 
where is the code i sent you?

where are the html / head / title and body tags necessary for a html page?



 
That worked shadow?

...simonchristieis
i Put the code in the head like you said? if my form is called formReg is form[0] still valid?
 
yep, the code is what you see on the source page
Code:
<form action=test.php method=post>
Name : <input><br>
Pwd : <input><br>
<input type=submit value=&quot;Submit&quot;>
</form>

What browser are you using?

________
George, M
 
I have IE 6.0.3790(on Windows 2003)
You shouldnt have any problem then.
I didnt had any problem either.
Do you have more then 1 form?

________
George, M
 
Yes.. I have a search form on the left side and the login form
 
no, it would be


function checkKeyPressed() {
if (event.keyCode==13){
document.forms[&quot;formReg&quot;].submit();
}
}

good luck
 
Check the link again with 2 forms.
Php isnt the problem, was faster to post example there
Code:
<form action=&quot;test.php?1&quot; method=post>
Name : <input><br>
Pwd : <input><br>
<input type=submit value=&quot;Submit&quot;>
</form>

<form action=&quot;test.php?2&quot; method=post>
Name1 : <input><br>
Pwd1 : <input><br>
<input type=submit value=&quot;Submit1&quot;>
</form>

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top