Thursday, August 11, 2011

Reading disabled HTML fields on page submit


Hi folks,

This probably is not a very big solution, but might be useful for newbies. To prevent users from entering data in any textbox or dropdown, you can either use "readonly" or "disabled". Readonly works fine, apart from the fact that the interface of the fields won't look like they are uneditable. Apart from that if it works for you, then its fine.

For "disabled"  option, not only the entire fields becomes uneditable, but also the interface has the feel that it is disabled. The biggest problem with disabled fields is if the form is submitted, the disabled fields are not submitted.


If you face a scenario where you absolutely have to use disabled fields and yet post the values in form submit, then a quick fix would be
to create a hidden field with same name and default value as the disabled field. So when the form is submitted, it works the way you wanted it to.

This probably is not the best solution, but is a quick fix.

Hope it helps







No comments:

Post a Comment