开发者

Safari/Chrome Not Posting Values When Changed Via Javascript

开发者 https://www.devze.com 2023-02-08 22:58 出处:网络
I have a few hidden form elements like so: <input type=\"hidden\" name=\"numberOfAdults\" /> I then have an onsubmit function that does some addition and puts the sum into the hidden fields:

I have a few hidden form elements like so:

<input type="hidden" name="numberOfAdults" />

I then have an onsubmit function that does some addition and puts the sum into the hidden fields:

form.numberOfAdults.value = numAdults;

The form is submitted depending on if this function returns true or false. When the form is submitted, IE7+ and Firefox show the changed value from the onsubmit function. Safari and Chrome do not. However, if I give the hidden inputs default values:

    <input type="hidden" name="numberOfAdults" value="2" />

Then the value gets passed. Why are Safari and Chrome ignori开发者_运维知识库ng these changed values?

EDIT: Here is the complete code: http://jsfiddle.net/2q8SX/


just a wild guess:

give your submit button:

onclick="yourFunction(); return false;"

and add to your function() as it's last command:

document.getElementByTagName('form').submit();
0

精彩评论

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