facha
facha

Reputation: 12502

html: how to uncheck a checked checkbox

I have an html form with a checked checkbox:

<input type=checkbox name="somebox" value="somevalue" checked />

When I get this form, uncheck the checkbox and post the form again, the checkbox is still being passed on together with submitted data. So, unchecking in does nothing finally.

Is there a way to uncheck it? Or may be there is another way to indicate that the checkbox is checked (without using "checked" keyword)?

Thanks in advance

UDP Finally it was a bug in another place. Checkbox logics is all right. Thanks everyone.

Upvotes: 0

Views: 1284

Answers (3)

Alex K.
Alex K.

Reputation: 175768

If its not checked the name may be passed (often libraries do this when building a request) but the value will not, so if the value of somebox is not somevalue, its not checked.

See How come checkbox state is not always passed along to PHP script?

Upvotes: 0

Syd
Syd

Reputation: 1546

If you have unchecked the checkbox, the "somebox" will not be passed a request parameter.

You must have made a mistake somewhere else.

Upvotes: 1

griegs
griegs

Reputation: 22760

You could use javascript or jQuery to uncheck it but that's hardley solving the problem.

Sounds like your fighting with viewstate and you'll either need to place this in an update panel, or out side the panel depending on needs, or in your code behind set the checked value of the control before you come back to the page.

get rid of the "checked" property in the control might also be a good start as everytime it comes back from a post it will try to check the box. instead, set it's checked state in the code behind.

Upvotes: 1

Related Questions