Forums

Possible to disable 'Enter' key as submit?

sinemac 24 Mar, 2009
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
GreyHead 24 Mar, 2009
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
sinemac 24 Mar, 2009
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
indra2004_id 27 Mar, 2009

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
Max_admin 27 Mar, 2009
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
indra2004_id 29 Mar, 2009
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
sinemac 29 Mar, 2009
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:
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
Max_admin 30 Mar, 2009
Thanks Scott!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.