By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,551 Members | 2,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,551 IT Pros & Developers. It's quick & easy.

How to give a value to non selected checkbox

P: n/a
M
Hello,

I would like to get a value for a non selected checkbox in a form.

Imagine my form contains :

<input type='checkbox' name='t[0]' value='1'>
<input type='checkbox' name='t[1]' value='1'>

When I analyse $t, if first checkbox is not selected and second is, I have :
$t[0] has no value. $t[1] equals 1
and count($t) equals 1

I would like to find a way to get :
$t[0] equals 0. $t[1] equals 1
and count($t) equals 2

Any idea ?

Thanx
M
Apr 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Can you explain why you want to get the value? It might help with the
answer.

Apr 25 '06 #2

P: n/a

M wrote:
Hello,

I would like to get a value for a non selected checkbox in a form.

Imagine my form contains :

<input type='checkbox' name='t[0]' value='1'>
<input type='checkbox' name='t[1]' value='1'>

When I analyse $t, if first checkbox is not selected and second is, I have :
$t[0] has no value. $t[1] equals 1
and count($t) equals 1

I would like to find a way to get :
$t[0] equals 0. $t[1] equals 1
and count($t) equals 2


You can "pre-initialize the values by using a hidden field. That way if
the checkbox isn't checked, the value from the hidden field will get
passed back. If it is checked, you get the checked value:

<input type="hidden" name="t[0]" value="0">
<input type="hidden" name="t[1]" value="0">
<input type='checkbox' name='t[0]' value='1'>
<input type='checkbox' name='t[1]' value='1'>

Ken

Apr 25 '06 #3

P: n/a
M
Thank you Ken.
This is *exactly* what I needed.

M
M wrote:
Hello,

I would like to get a value for a non selected checkbox in a form.

Imagine my form contains :

<input type='checkbox' name='t[0]' value='1'>
<input type='checkbox' name='t[1]' value='1'>

When I analyse $t, if first checkbox is not selected and second is, I have :
$t[0] has no value. $t[1] equals 1
and count($t) equals 1

I would like to find a way to get :
$t[0] equals 0. $t[1] equals 1
and count($t) equals 2


You can "pre-initialize the values by using a hidden field. That way if
the checkbox isn't checked, the value from the hidden field will get
passed back. If it is checked, you get the checked value:

<input type="hidden" name="t[0]" value="0">
<input type="hidden" name="t[1]" value="0">
<input type='checkbox' name='t[0]' value='1'>
<input type='checkbox' name='t[1]' value='1'>

Ken

Apr 25 '06 #4

P: n/a
M wrote:
I would like to get a value for a non selected checkbox in a form.


Have a look at the Javascript code generated by PEAR::QuickForm for
the advcheckbox element.

/Marcin
Apr 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.