HTML form default values override actual values at post time in Internet Explorer 9

寵の児 提交于 2019-12-11 14:07:58

问题


I am just testing the brand new Internet Explorer 9 Beta with my website. I see a weird behaviour for some form values and I am not sure if it is my mistake or a bug in IE9. What do you think?

I have one form which declares several hidden input fields like this

<input type="hidden" name="NewStatus" />
<input type="hidden" name="lastSaveStatus" value="" />

When the page is being submitted, the values are saved like this (in JavaScript):

newStatus.setAttribute("value", myNewStatus);
var formLastStatus = document.getElementsByName("lastSaveStatus")[0];
formLastStatus.setAttribute("value", lastSaveStatus);
alert(lastSaveStatus);
alert(formLastStatus.getAttribute("value"));
var form = document.getElementById("myForm"); 
form.submit();

That code has worked for years and across all browsers. The alerts already indicate that I have now a problem with the lastSaveStatus field. In IE9 the NewStatus is correctly transmitted to the server (means that I can access the value in ASP.NET using Request.Form["NewStatus"]). But the value for "lastSaveStatus" is always "".

As you can see I used a value="" in the definition of my hidden field. If I remove this default value, the new value is correctly transferred to the server. If I use a default value, always the default value is transferred.

Any idea why this is happening?


回答1:


Are you sure this worked in previous versions of IE? I've always had problems with that syntax in IE/Win, the following should work however:

formLastStatus.value = lastSaveStatus;

The above should work in all browsers, too.



来源:https://stackoverflow.com/questions/3724207/html-form-default-values-override-actual-values-at-post-time-in-internet-explore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!