Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple checkboxes question

Status
Not open for further replies.

786snow

Programmer
Nov 12, 2006
75

Hi,

I want to have an array of checkboxes, thats how I have declared them. but when I submit my form, on my
javaservlet even thought I have boxes checked , values come as null. What am I doing wrong here?


<TR>
<td><INPUT TYPE=checkbox NAME=check_all VALUE=E ID="check_all" >
<b>Select all documents</b></td>
</TR>
<tr>
<td><div class="indent"><input type="checkbox" id="check_all" name="check_all"
value="E"/ > Account statements </div></td>
</tr>

<tr>
<td><div class="indent"><input type="checkbox" id="check_all" name="check_all"
value="E"/ > Account statements </div></td>
</tr>

<tr>
<td><div class="indent"><input type="checkbox" id="check_all" name="check_all"
value="E"/ > Account statements </div></td>
</tr>


Thanks
 
Well, each checkbox has the same id, name and value. The resulting data won't tell you much.

Each ID must be unique.
The names need to be the same as they are part of the same checkbox group.
The values need to be different for each.

As for the data being 'null', it could be because of what I said above or it could be your script.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
thanks, You are right , I think because of same ID it did not work. Do you think it will be beter just to have it defined with out the id , as if I do not write ID it will be automaticcally created, as check_all[0], check_all[1], , in other words have it like



<TR>
<td><INPUT TYPE=checkbox NAME=check_all VALUE=PE >
<b>Select all documents</b></td>
</TR>
<tr>
<td><div class="indent"><input type="checkbox" name="check_all"
value="SE"/ > Account statements </div></td>
</tr>
 
The names need to be the same as they are part of the same checkbox group.
The values need to be different for each.

I thought that was for radio buttons only, and that for checkboxes, you gave each a different name/id, with any value you wanted?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
To create an array of check boxes , I believe you need to have same name for all the boxes, this way it will create an array of check boxes, I got the following example at the net


*************************

<input type="checkbox" name="Liked" value="Cool Layout">Cool Layout

<input type="checkbox" name="Liked" value="Easy to Navigate">Easy to Navigate

<input type="checkbox" name="Liked" value="Great Contents">Great Contents


function CheckLikes() {

boxes = document.f1.Liked.length
txt = ""
for (i = 0; i < boxes; i++) {
if (document.f1.Liked.checked) {
txt = txt + document.f1.Liked.value + " "
}
}


if (txt == "") {
Message = "No Boxes ticked"
}
else {
Message = ""
}

return Message
}

**********************
 
BRPS, yes I was thinking of radio buttons (duh! me)... and you are right about the PHP array thing too.
Not sure about naming when using JS though. Logic would say it would be something similar, but I've never tried it.


<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Also the value for a checkbox if checked is "on" and the value for a checkbox that isn't checked is '' at least in PHP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top