not checked checkboxes input are not sent by the browser

L

lehmann

Hello,

I discovered that in a form with checkboxes input, if the checkboxe is
not checked, not value is sent in my request by the browser (at least
IE, I think it is ok in NS).
But I my application I need to get the input even if it is not checked
(my form is dynamic and I distinguish the cases: input exists and is
cheched / input exists ans is not checked / input doesn't exists)
I know I could use another input such as textfield, but I wonder if
there is another solution that would allow me to keep the checkboxe
and send it even if not checked.
Thanks for any help!
G.
 
D

David Dorward

lehmann said:
Hello,

I discovered that in a form with checkboxes input, if the checkboxe is
not checked, not value is sent in my request by the browser (at least
IE, I think it is ok in NS).

Its "OK" in all browsers.

Unchecked checkboxes are not submitted, that is how it is supposed to work.
But I my application I need to get the input even if it is not checked

Then test for the _existance_ of the variable rather then its value.
(my form is dynamic and I distinguish the cases: input exists and is
cheched / input exists ans is not checked / input doesn't exists)

Then you should include an input that specifies which checkboxes exist.
 
D

Daniel

But I my application I need to get the input even if it is not checked
(my form is dynamic and I distinguish the cases: input exists and is
cheched / input exists ans is not checked / input doesn't exists)
I know I could use another input such as textfield, but I wonder if
there is another solution that would allow me to keep the checkboxe
and send it even if not checked.

You say it's dynamic, so just in case it's anything like mine - I'm doing
something with PHP & MySQL, this is what I did. I put a hidden field in the
form and link it to the checkbox, like this (a checkbox to click whether or
not a user's address should be visible on my site):

<input name="showaddressControl" type="checkbox" id="showaddressControl"
value="showaddressControl" onClick="this.form.showaddress.value =
((this.checked)?1:0)">
<input name="showaddress" type="hidden" value=""
onChange="this.form.showaddressControl.checked =
((this.value==1)?true:false)">

The first input is the checkbox, and when it's clicked, it sets the hidden
value to 1 (MySQL for TRUE) if the checkbox is checked, and 0 (FALSE) if
it's not.

The second input is the actual value that I get and put from/to the
database. The reason I have an onchange handler in it is that I dynamically
fill it with data on different persons, so whenever its value changes, the
checkbox is changed too to reflect the new value. You could give it a
default value of "null" or "not set" or something to show when 'input
doesn't exist').

Hope this has something to do with what you're doing and that it will help
;)

Cheers,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top