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).
A disabled input element is unusable and un-clickable. The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable.
To submit the value of a disabled input field with HTML, we replace the disabled attribute with the readonly attribute. to set the readonly attribute to readonly . This way, the user won't be able to interact with the input, but the input value will still be submitted.
The difference between disabled and readonly is that read-only controls can still function and are still focusable, whereas disabled controls can not receive focus and are not submitted with the form and generally do not function as controls until they are enabled.
We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.
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.
If you don't want it changed, make it readonly
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With