Skip to main content
Inspiring
May 18, 2006
Answered

Hitting Enter Key with online form

  • May 18, 2006
  • 3 replies
  • 498 views
When my users hit the enter key instead of clicking on submit, it just reloads the form and doubles any url variables that I'm passing. The page reloads itself

<cfif isDefined('form.submit')>
Perform actions
<cfelse>
Display form
</cfif>

The url would be http://192.168.1.1/test.cfm?cfid=3455 When the use hits enter it becomes http://192.168.1.1/test.cfm?cfid=3455cfid=3455. and just keeps adding everytime the user hits enter instead of clicking submit. Is there a way to make the enter key select the submit button by default?

Thanks!
This topic has been closed for replies.
Correct answer Xtort
Thanks the scritp you supplied worked like a charm!!

Sincerely,
Pauly

3 replies

Inspiring
May 18, 2006
Do you have an action assigned to the form tag? The only time I have run
into this situation the client didn't have an action assigned in the form
tag.

--
Bryan Ashcraft (remove brain to reply)
Web Application Developer
Wright Medical Technologies, Inc.
=============================
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


"Xtort" <webforumsuser@macromedia.com> wrote in message
news:e4ihm0$g93$1@forums.macromedia.com...
> When my users hit the enter key instead of clicking on submit, it just
> reloads
> the form and doubles any url variables that I'm passing. The page reloads
> itself
>
> <cfif isDefined('form.submit')>
> Perform actions
> <cfelse>
> Display form
> </cfif>
>
> The url would be <a target=_blank class=ftalternatingbarlinklarge
> href=" http://192.168.1.1/test.cfm?cfid=3455">http://192.168.1.1/test.cfm?cfid=34
> 55</a> When the use hits enter it becomes <a target=_blank
> class=ftalternatingbarlinklarge
> href=" http://192.168.1.1/test.cfm?cfid=3455cfid=3455.">http://192.168.1.1/test.c
> fm?cfid=3455cfid=3455.</a> and just keeps adding everytime the user hits
> enter
> instead of clicking submit. Is there a way to make the enter key select
> the
> submit button by default?
>
> Thanks!
>


Inspiring
May 18, 2006
Strictly a guess because you are not showing your form code, but, are you using method = "get" in your form? That might be messing it up. With a normal html form, the enter key will almost always submit the form.
Inspiring
May 18, 2006
You need to catch the Enter key press and kill it or convert it. You can kill the Enter keypress or convert it with the following:

<head>
<script>
function kill_enter(kc){
if(kc==13){
//return event.keyCode=9; //moves cursor to next input
return false; //kills the keypress
}
}
</script>
</head>

<form name="myform2">
<input type="text" name="y" onKeyDown="return kill_enter(event.keyCode);">
<input type="text" name="z" onKeyDown="return kill_enter(event.keyCode);">
<input type="submit">
</form>

Put the onKeyDown line on each input box but not the submit button.


XtortAuthorCorrect answer
Inspiring
May 19, 2006
Thanks the scritp you supplied worked like a charm!!

Sincerely,
Pauly