views:

131

answers:

2

Hi,

Hoping someone can assist or point me in the right direction to another thread/url with regards to disabled checkboxes.

I basically have a couple of checkboxes in my form, that are not database items but am retrieving the source value based on a database column.

As I do not want the user to be able to change these checboxes, I have disabled these checboxes

When I query a record, the form at start-up retrieves the value for the checkbox with no issues.

The problem is, when I hit a validation error on my form when the page is submitted, my checkbox values that were originally retrieved as 'Y', i.e checked are now null.

Can anyone pls assist with what is going on or a workaround inorder to maintain these values when a validation error occurs.

Thanks.

+1  A: 

A disabled control will not be successful (that's the point of disabled).

Either go with a readonly control instead, or use a hidden input.

David Dorward
Can you please provide an example of a hidden input checkbox - thanks.
tonsils
A "hidden input" not a "hidden input checkbox". `<input type="hidden" name="foo" value="bar">`
David Dorward
Thanks David but based on this, how can I maintain the value of the checkboxes after a validation failure due to some other field requiring an input? I basically need to get the checkbox to the state it was prior to validation failure.
tonsils
I have no idea how your system is structured. So I don't know how you could find out that previous value.
David Dorward
No worries David - appreciate your help.
tonsils
A: 

You can enable the checkboxes in question just before you post the form. Then they will be "just sent back", (hopefully) untouched.

As always, you must do your server side checks and not expect that form values and/or javascript have not been tampered with.

npup