• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Hitting Enter Key with online form

Explorer ,
May 18, 2006 May 18, 2006

Copy link to clipboard

Copied

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!
TOPICS
Advanced techniques

Views

396

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 19, 2006 May 19, 2006
Thanks the scritp you supplied worked like a charm!!

Sincerely,
Pauly

Votes

Translate

Translate
Contributor ,
May 18, 2006 May 18, 2006

Copy link to clipboard

Copied

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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2006 May 19, 2006

Copy link to clipboard

Copied

LATEST
Thanks the scritp you supplied worked like a charm!!

Sincerely,
Pauly

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2006 May 18, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2006 May 18, 2006

Copy link to clipboard

Copied

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!
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation