开发者

button type value is different in IE & FF

I'm using a form containing a button type shown below:

<form method="post" action="">
<button type=submit value="hello" name="submitform">World</button>
</form>

Here the button type shows different behavior on different browsers

now print_r($_POST) display

Array
(
    [submitform] => World
)
 In IE(v 7.0) 

whereas

Array
(
    [submitform] => Hello
)
in FF(v 3.5) 

Why does it display different value... now my questions are:

  1. I 开发者_JAVA百科want [submitform]=Hello in both browser and I don't want to change the value 'World' outside of <button>

  2. Is <button type="submit"> or <input type="submit"> better


You could substitute the button's information with a hidden input field:

<form method="post" action="">
  <button type="submit">World</button>
  <input type="hidden" name="submitform" value="hello" />
</form>

This is a browserquirks save method.

Another possibility, although way less elegant, is to use an image:

<form method="post" action="">
  <input type="image" src="my_World_image.gif" name="submitform" value="hello" />
</form>

Advantage: You can have multiple submit buttons submiting different values.

Disadvantage: As David Dorward mentioned, most probably you will face the same problem again because of buggy implementations, namely IE's.

The third possibility is JavaScript, but you will encounter all sorts of problems for users having disabled it (I warned you!):

<input type="hidden" name="submitform" value="" id="changeme" />
<button type="button" onclick="do_submission('hello')">Submit Hello</button>
<button type="button" onclick="do_submission('world')">Submit World</button>

<script type="text/javascript">
function do_submission(value) {
  document.getElementById('changeme').value = value;
  document.getElementsByTagName('form')[0].submit();
}
</script>


I always use <input type="submit" value="Whatever I want the button label to be" /> and it's worked nicely.


Well with button you can have arbitrary text or images inside the button. This is not possible with input afaik. The value is always also the buttons text.

If IE has this strange behaviour then it seems you have no other choice as to keep the value of the button and the text in it the same (which is exactly what input is doing).


<button> is horribly broken in MSIE. <input type="submit"> doesn't let you have the label be different to the value.

The work around is to use <input type="submit"> and give each one a unique name, then search to find which one was successful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜