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

How to set default button when press "Enter"

Guest
Feb 02, 2012 Feb 02, 2012

Hi,

I have a form and it has only one button (Submit). When I press "Enter", it can submit the form and do the action. However, when I add another button (Normal button, not submit), it cannot perform submit action directly when I press "Enter".

If we press "Enter" and the form can submit automatically, it is more user-friendly than without this feature. Therefore, may I know the method of set the default button when users press "Enter"?

1.4K
Translate
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

LEGEND , Feb 02, 2012 Feb 02, 2012

At first I thought the order of the form controls might matter.  When I run this code:

<cfdump var="#GetTickCount()#">
<form action="TestCfgrid.cfm" method="post">
<input name="x" type="text" />
<input type="button" value="x" />
<input type="submit" />

</form>

While I am in the text box, if I press the enter key the form submits.  I originally tried it with the submit and button inputs in the opposite order.

Note that the enter button will not submit the form if you are in a select control (aka dropdown

...
Translate
LEGEND ,
Feb 02, 2012 Feb 02, 2012

What does the other button do?

Translate
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
Guest
Feb 02, 2012 Feb 02, 2012

The new button is used to call the cfc for opening a new sub-window. After some data selection, it sets the result to the form field. Therefore, the button is just set as a normal button. No Submit or Reset will be performed by clicking this button.

Translate
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 ,
Feb 02, 2012 Feb 02, 2012
LATEST

At first I thought the order of the form controls might matter.  When I run this code:

<cfdump var="#GetTickCount()#">
<form action="TestCfgrid.cfm" method="post">
<input name="x" type="text" />
<input type="button" value="x" />
<input type="submit" />

</form>

While I am in the text box, if I press the enter key the form submits.  I originally tried it with the submit and button inputs in the opposite order.

Note that the enter button will not submit the form if you are in a select control (aka dropdown) or a textarea or if your focus is not on a form element.  That's the default behaviour.  If you want to override that, you'll have to write some javascript.

Translate
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