How can I disable an input field without affecting the field value in a PHP form?
I am creating a demo page where some settings fields need to be disabled. I tried to disable the input with the remaining unused value, just greyed out. I disabled the input with disabled = "true". When the form is submitted, the value disappears, even though it was before. How can I prevent the value from disappearing while disabling the specified fields?
source to share
disabled
form fields are not submitted under any circumstances.
The most common way to avoid this problem is to make them readonly
and add a input[readonly] { ... }
css rule to make the text gray like in a disabled box.
You can also use JavaScript to prevent it from focusing; might look like this if you have jQuery:
$('input[readonly]').live('focus', function(e) {
$(this).blur();
});
source to share
If you want the value to be displayed and not changed, you can use readonly
<input type="text" name="xxx" value="xxx" readonly="readonly" />
If you want the value to be hidden and sent to the action file you can use type = hidden
<input type="hidden" name="xxxx" value="xxx" />
More details on the HTML input tag can be found here http://www.w3schools.com/tags/tag_input.asp
source to share
Just drop offers here.
You can disable this field as usual with Javascript, but before disabling the field, you can use Javascript to enter the value of this field into the hidden field.
function runme() {
var newval = $('#field1').val();
$('#hiddenfield').val(newval);
$('#field1').attr('disabled', 'disabled');
}
<input id="field1" name="field1" type="text" value="this val" />
<input id="hiddenfield" name="hiddenfield" type="hidden" />
<input type="button" onclick="runme();" />
source to share