In testing a new form, I've had a couple of testers submit the form before they'd completed it because they hit the "Enter" key. I know it's pretty normal for "Enter" to result in submitting a form if the cursor is not in a field that accepts "Enter" for line breaks, but I'm wondering if it's possible to disable this?
What would be needed to make it so that "Enter" can't work as an alternative to clicking on the Submit button?
Thanks,
Scott
What would be needed to make it so that "Enter" can't work as an alternative to clicking on the Submit button?
Thanks,
Scott
Hi Scott,
I think that there are some JavaScript solutions - Google will find you some suggestions.
You could also make a required field near the end so that people will get a validation error if they submit too early.
Bob
I think that there are some JavaScript solutions - Google will find you some suggestions.
You could also make a required field near the end so that people will get a validation error if they submit too early.
Bob
Thanks Bob. I did think about the required field near the end, but I've also found some javascript solutions that I may try.
Scott
Scott
Thanks Bob. I did think about the required field near the end, but I've also found some javascript solutions that I may try.
Scott
Please share the code here, so that others (including me :wink:) can get the benefit as well
Hi indra,
I wish Scott will share his code but a quick Google search will bring some useful results, "JS disable submit enter clicked" or so ?
Cheers,
Max
I wish Scott will share his code but a quick Google search will bring some useful results, "JS disable submit enter clicked" or so ?
Cheers,
Max
Hi Max,
Thanks a lot.
A quick try shows plenty of information.
However, I have no time to do the experiment now.
I'll try it later and share it here once I find the trick.
Regards,
Indra
Thanks a lot.
A quick try shows plenty of information.
However, I have no time to do the experiment now.
I'll try it later and share it here once I find the trick.
Regards,
Indra
Hi,
Sorry I didn't post the solution I used earlier - had to take my laptop in to have the logic board replaced, so I wasn't fully online for a few days.
Here's the code I used to disable the Enter key acting as "Submit" -- put this in the "Form JavaScript" form code area:
I don't recall now where I found this - and I do think there was something about being able to disable the "Enter" key within specific fields also by adding a 'class=' element, but I don't remember what that was exactly (since I didn't need it, I didn't pay attention to that part).
Hope this helps.
Scott
Sorry I didn't post the solution I used earlier - had to take my laptop in to have the logic board replaced, so I wasn't fully online for a few days.
Here's the code I used to disable the Enter key acting as "Submit" -- put this in the "Form JavaScript" form code area:
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
I don't recall now where I found this - and I do think there was something about being able to disable the "Enter" key within specific fields also by adding a 'class=' element, but I don't remember what that was exactly (since I didn't need it, I didn't pay attention to that part).
Hope this helps.
Scott
Thanks Scott!
Max
Max
This topic is locked and no more replies can be posted.