Forum Moderators: open

Message Too Old, No Replies

Stopping IE from submitting form on "Enter".

         

msr986

11:50 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE wants to submit your form when you hit the "enter" key.

Anyone know how I can stop this behavior?

keyplyr

5:36 am on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't hit the "enter" key.

bobriggs

6:02 am on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As keyplr said, that's the default behavior.

Throw in some .js that checks input, if it's blank, then force the user to fill in some more blanks.

If they get past that, on the server side, of course, you should check all the inputs and let the user know that they pressed enter or clicked submit before all data was filled in.

Learning Curve

6:17 am on Oct 23, 2002 (gmt 0)

10+ Year Member



<textarea> doesn't have the automatic submit behavior of <input> but it has other problems.

joshie76

8:25 am on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to remove the default behaviour by making the form submit using javascript.

Firstly, don't have a type="submit" input tag, use a button with an onclick event that calls a javascript function that submits your form. In the form tag add an onsubmit event handler that returns false (this stops the form being submitted directly by the user (on "enter") but will allow it through JS.

eg:

<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>

<form name="myform" onsubmit="return false;">
<input type="text" value="Hi">
<input type="button" onclick="submitform()">
</form>

Remember that any visitor would have to have JavaScript enabled to be able to submit a form like this though.

Josh