[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Clicking enter does not submit the form

Hello,

I have several forms on one page.

When I hit enter it does not post the data from the form I am current in and post it to the correct page.

I have to hit submit in order for it to work correct.

Does this have to do with my isset logic in my code?  I use the isset to determine what submit box is selected.
Thanks.
0
Codeit1978
Asked:
Codeit1978
  • 3
  • 2
1 Solution
 
Brian BushSolutions ArchitectCommented:
If you have more than one field per form, enter will not submit.
I will post you the code to capture the enter key.

--brian
0
 
Brian BushSolutions ArchitectCommented:
This is an example of how to trap the enter key and have it submit a form.
You may have to do some troubleshooting for making it work across platforms.

<HTML>
<HEAD>
    <SCRIPT LANGUAGE=JAVASCRIPT>
        function TrapKey(form) {
            if (window.event) {
                if (window.event.keyCode == 13) {
                    form.submit();
                }
            return false;
            }
        }
    </SCRIPT>
</HEAD>
<BODY ONLOAD="FORM1.FIELD1.focus();">
    <FORM ID="FORM1" ONKEYDOWN="TrapKey(this)">
        <INPUT TYPE="TEXT" NAME="FIELD1" VALUE="value1"><BR>
    </FORM>
    <FORM ID="FORM2" ONKEYDOWN="TrapKey(this)">
        <INPUT TYPE="TEXT" NAME="FIELD2" VALUE="value2"><BR>
        <INPUT TYPE="TEXT" NAME="FIELD3" VALUE="value3"><BR>
    </FORM>
    <FORM ID="FORM3" ONKEYDOWN="TrapKey(this)">
        <INPUT TYPE="TEXT" NAME="FIELD4" VALUE="value4"><BR>
        <INPUT TYPE="TEXT" NAME="FIELD5" VALUE="value5"><BR>
        <INPUT TYPE="TEXT" NAME="FIELD6" VALUE="value6"><BR>
    </FORM>
</BODY>
</HTML>

--brian
0
 
Codeit1978Author Commented:
This looks perfect, let me give it a go
0
 
Codeit1978Author Commented:
Humm that's not working it's almost like it's not passing the form.  Did this work for you?
0
 
Brian BushSolutions ArchitectCommented:
Yup. It works for me with Internet Explorer version 6 in Windows.
These forms are set to GET so the values should show up in the address bar.

Anyway, hitting enter to submit a form is convenient, but it is good form to
always have a button to submit it manually.
--brian
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now