admin管理员组文章数量:1279112
I have a button tag as supposed to and input tag, which has different text to what I what its value to do, see below.
<button value="<%=RS("field1")%>" name="change" id="change">Change</button>
This works dandy in Firefox, but in IE.. dun,dun,dunnnn... the value of the button es back as the word "change" which is meant to be the text the button displays.
I would usually just use and input tag but I think I can only use a button tag
Is there anyway to get round this?
I have a button tag as supposed to and input tag, which has different text to what I what its value to do, see below.
<button value="<%=RS("field1")%>" name="change" id="change">Change</button>
This works dandy in Firefox, but in IE.. dun,dun,dunnnn... the value of the button es back as the word "change" which is meant to be the text the button displays.
I would usually just use and input tag but I think I can only use a button tag
Is there anyway to get round this?
Share Improve this question edited Aug 19, 2024 at 7:15 VLAZ 29.1k9 gold badges62 silver badges84 bronze badges asked Dec 15, 2010 at 13:36 HayleyHayley 311 silver badge2 bronze badges6 Answers
Reset to default 6From w3schools.:
Important: If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the
<button>
and</button>
tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.
Therefore, What you should do is <input type="button" />
What I've generally done in situations like this is to embed the information in the name
attribute so you'd have
<button name="change:<%=RS("field1")%>" id="change:<%=RS("field1")%>">Change</button>
then use the server-side code to discard the returned value and then depose the name back into a {name, value) pair.
(Note that your "id"s need to be unique anyway.)
As far as I know there is no way around it. It's simply the way IE handles the button tag, it will send the text between the opening and closing tag.
Considering you can't use a normal input tag for the button, how about using a hidden field to convey the method you want to use?
<form action="somepage" method="POST">
<!-- some fields here -->
<input type="hidden" name="action" value="<%=RS("field1")%>" />
<button name="change" id="change">Change</button>
</form>
Seems to me the desired value is always in the button "value" attribute (since that's the value the other browsers submit), so why not simply:
<button ... onclick="this.innerHTML=this.value;" ... >
IE8 does send the value, so it's IE7 only (probably 6 too but who cares) problem.
Anyhow, one possible trick is to put the value as part of the text, hidden, then in the button click event (using JavaScript) change the button text to that value.
The final result would look like this:
<button value="<%=RS("field1")%>" name="change" onclick="this.innerHTML = this.childNodes[1].innerHTML;"><span>Change</span><span style="display: none;"><%=RS("field1")%></span></button>
Also, as you have this in loop, don't set the ID to avoid having more than one element sharing the same ID - it's invalid and if you need the ID for some reason, append something unique to it in each iteration.
As I described above, don't check value in pair {button_name,button_value} instead check only button_name exist in input set without checking its value.
本文标签: javascriptIE doesnt read the real button value How to get round thisStack Overflow
版权声明:本文标题:javascript - IE doesnt read the real button value! How to get round this? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741264597a2368223.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论