Will a disabled text field submit when a form is POSTed?

青春壹個敷衍的年華 提交于 2019-12-22 01:42:36

问题


If I submit a disabled text field via POST, what will the resulting value be on the action page?

For example, I have:

<table border=0 cellpadding=4 cellspacing=0>
<tr><td>
   <input type="checkbox" id="chk_$item" 
    onClick="javascript:handleClick('$item')">
</td><td>
   <input type="text" id="txt_$item" name="addresses[]" value="$item">
</td></tr>
<tr><td>
   ...etc...
</td></tr>
</table>

the handleClick() javascript function checks if chk_$item is checked, if not, it disables the txt_$item text field.

When I submit it, all of the text fields go to an addresses[] array in a PHP script.

But, can I prevent the field from submitting anything if it is disabled? Will it do this by default? If not, how should I change the behavior? (I really don't want to clear the fields when they get disabled).


回答1:


Disabled inputs will not be submitted with the form; that's part of the defined behavior of disabled, cf. W3C HTML 4.01 Form docs.




回答2:


If you don't want it changed, make it readonly.



来源:https://stackoverflow.com/questions/1215641/will-a-disabled-text-field-submit-when-a-form-is-posted

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