morpheus3g
asked on
document catch enter key
HI experts
i would like to submit the do a javascript action when the user press the 'enter' key while on my page .. even if the user doesn't press enter in a form field.
i would like to submit the do a javascript action when the user press the 'enter' key while on my page .. even if the user doesn't press enter in a form field.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi There,
I dont remember when, but somewhere... in the past.. I had to use document.all.
that's why when I am not sure about the browser version.. I use it :)
tnx for your input though
Regards,
Chinmay
I dont remember when, but somewhere... in the past.. I had to use document.all.
that's why when I am not sure about the browser version.. I use it :)
tnx for your input though
Regards,
Chinmay
The problem was not document.all, but the .Submit() call. It has to be .submit()
And document.all is a collection in IE where you can access any element in the document from any reference. But that is not necessary for the form objects.
And document.all is a collection in IE where you can access any element in the document from any reference. But that is not necessary for the form objects.
Hi Zvonko,
my mistake.... I accept....
;) tnx
Regards,
Chinmay
my mistake.... I accept....
;) tnx
Regards,
Chinmay
ASKER
i've noticed that it isnt working with mozilla.. i need something cross-platform...
Check this:
<BODY onkeypress="SubmitMyForm(e vent)">
<SCRIPT>
function SubmitMyForm(e){
var keyCode=(e.keyCode)?e.keyC ode:e.whic h;
if (keyCode==13){
document.forms[0].submit() ;
}
}
</SCRIPT>
<BODY onkeypress="SubmitMyForm(e
<SCRIPT>
function SubmitMyForm(e){
var keyCode=(e.keyCode)?e.keyC
if (keyCode==13){
document.forms[0].submit()
}
}
</SCRIPT>
ASKER
not working with firefox
This worked for me in FF1.0.3:
<BODY onkeypress="SubmitMyForm(e vent)">
<form>
</form>
</body>
<SCRIPT>
function SubmitMyForm(e){
var keyCode=(e.keyCode)?e.keyC ode:e.whic h;
if (keyCode==13){
alert("Submitting...")
document.forms[0].submit() ;
}
}
</SCRIPT>
Do you have a <form> tag on your page?
<BODY onkeypress="SubmitMyForm(e
<form>
</form>
</body>
<SCRIPT>
function SubmitMyForm(e){
var keyCode=(e.keyCode)?e.keyC
if (keyCode==13){
alert("Submitting...")
document.forms[0].submit()
}
}
</SCRIPT>
Do you have a <form> tag on your page?
ASKER
that won't for me.
ff 1.04
:(
ff 1.04
:(
You have elsewhere a typo.
Show your page html source. Or is your page online?
Show your page html source. Or is your page online?
The correct submit method name is this:
document.YourFormName.subm
Or to submit the first or only form on the page:
document.forms[0].submit()