Forms won’t submit in IE when pressing enter

Hi All

I’ve come across this issue yet again. Realised I’d forgotten to post it the first time.

Instance 1 – Form has 1 text field, when pressing enter the form doesn’t submit correctly, either won’t submit, or won’t send submit button value through to php.

Solution –

if ($noOfTextFields == 1)
//fix IE bug where if there is only 1 text field you can't press enter to submit form (it doesn't send submit button name value pair)
$output .= "<input name='" . time() . "' style='display: none;' type='text' / >";

That should fix that instance

Instance 2 – Only seems to be happening in IE8 – When a form is either being hidden (using CSS display or visibility tags) or being creating dynamically when you press enter nothing will happen

Solution – add the following code to your form tag – Special thanks to Chris from for providing me with an example he used to solve the ajax problem

onkeypress=" var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (keycode == 13) {this.submit()}else {return true;}"

Make sure that it’s all on one line you know how javascript dislikes multiple lines.

Good luck to you all. If you find any other occurrences of this problem that aren’t covered here let me know

You can leave a response, or trackback from your own site.

Leave a Reply