-2
<input type="checkbox" disabled="disabled" checked="checked" name="is_ok" id="id_is_ok"/>

How to add default value of this input? (This input is disabled)

If this field in disabled If I edit my data, this value is not saved.

amarkon
  • 91
  • 1
  • 5

2 Answers2

2

Yes, if the field is disabled, it is not send when the form is submitted. If you want to have a field that cannot be edited but is submitted with the form, use readonly="readonly" instead.

Edit: Argh, this does not work, readonly is ignored for checkboxes, see comment below. Instead if you want to send that field value on submit, you can define a second hidden field with the same name and value:

<input type="checkbox" disabled="disabled" checked="checked" name="is_ok" />
<input type="hidden" name="is_ok" id="is_ok_hidden" value="some value here" />

(You can give that field a value="some value here" like any other html input field, and set that value via element.setAttribute("value","some other value") in JavaScript. As only value of the type="hidden" field is send, only set the value of that field and ignore the value for the checkbox.)

Clemens Klein-Robbenhaar
  • 3,457
  • 1
  • 18
  • 27
  • Uh, indeed you can change a `readonly` checkbox :( I have to admit that I never really tried until now. Seems the `readonly` attribute is ignored for checkboxes. Maybe you can still go the `disabled` way and send a hidden input field with it, like ``. Quite a kludge, I have to admit. – Clemens Klein-Robbenhaar Feb 07 '13 at 13:26
1
   <input type="checkbox" disabled="disabled" checked="checked" name="is_ok" value="bike" id="id_is_ok"/>

here bike is default value...

Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57