3cho

Friday, November 03, 2006

Didn't know this until I tested it

If you submit the form below by clicking the submit button, then the value of the submit button is posted in both IE and firefox. However if your focus is in the input box and you hit the 'enter' key to submit the form, then IE and firefox differ. IE will not post the either submit button values, but firefox will post the first submit button (save). This is also true if the form only has one submit button.

Handy to know incase you have more than one submit button and your server-side logic inspects the post vars for which submit button was used to submit the form. Your server-side code will have to have knowledge of how you submit buttons are ordered on the screen, since the first submit button will be used to submit the form and IE will not tell you which one was used to submit the form. if you want consistent results between Firefox and IE, your servers-side logic will make the first submit button on the screen the default action if it does not receive a submit value in the post vars.

<form name='postTest' method='POST'>
<input type='text' name='input1' value='some value1'>
<input type='submit' name='action11' value='Save1' >
<input type='submit' name='action12' value='Delete1' >
</form>


<form name='postTest2' method='POST'>
<input type='text' name='input2' value='some value2'>
<input type='hidden' name='hidden2' value='some hidden value2'>
<input type='submit' name='action22' value='Delete2' >
<input type='submit' name='action21' value='Save2' >
</form>

2 Comments:

  • It's interesting you posted this, because I just came across this issue yesterday.

    The main thing, as you said, is that IE doesn't post the default submit button name to the post array when the Enter key is pressed while the form is active. But Firefox does.

    However, even when you click a submit button, only one button name is ever posted. And, of course, it will be the button that was clicked. So, on the server-side, if you want to know which button was pushed, you really have to check for all button names.

    If don't find any button names in the post array, then you can assume the default button was pushed. This is because any other way of submitting the form would have put a button name in the post array.

    By Blogger Dean, at 11:33 p.m.  

  • exactly

    By Blogger Shane, at 10:00 a.m.  

Post a Comment

<< Home