Copy link to clipboard
Copied
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"?
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
...Copy link to clipboard
Copied
What does the other button do?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.