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

submit the form by pressin enter

Status
Not open for further replies.

nirmalgupta

IS-IT--Management
Sep 12, 2001
35
IN
Hi ,
I want to submit the form when user press enter on any of the textbox of that form. This should work in both IE and Netscape.
TIA
Nirmal
 
Hello,

This is possible with a litlle javascript.
An example:
Code:
<form id=&quot;fsub&quot; action=&quot;[URL unfurl="true"]http://www.freejavascripts.f2s.com/&quot;>[/URL]
<input type=&quot;text&quot; onkeydown=&quot;if(k7=window.event.keyCode == 13) fsub.submit()&quot;>
</form>
My site: msn/email: matthiasdeschagt@hotmail.com
 
Hi,
your code works fine, but when i use this funda in my page, i get the error, window.event is invalid ( in netscape).
I am copying the code also.one thing more. Is there any specific reason to use k7? and how it is working in netscape?
thanx
Nirmal
 
I'am sorry
the script is wrong.
this is the correct script:
Code:
<form id=&quot;fsub&quot; action=&quot;[URL unfurl="true"]http://www.freejavascripts.f2s.com/&quot;>[/URL]
<input type=&quot;text&quot; onkeydown=&quot;if(window.event.keyCode == 13) fsub.submit()&quot;>
</form>
My site: msn/email: matthiasdeschagt@hotmail.com
 
this one will work in both. put this in your header (replace FormNAme with the name of your form)...

function checkKey(e) {
if(document.all) {
if(event.keyCode == 13) {
document.FormName.submit()
}
} else if(document.layers) {
if(e.which == 13) {
document.FormName.submit()
}
}
}


and put onkeyDown=&quot;checkKey()&quot; in your form tag.

 
this seems to work fine with ie5.5 and up....but having problem with ie5.0. it just does not seem to submit the page, no error though... any suggestions?

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top