how to validate array check box in php

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

how to validate array check box in php

Post by manojsemwal1 »

hai using the following array check box in my php script

<input type ="checkbox" name="sel[]" value="<?php echo $b[TempID]; ?>"></div>
its inside the while loop.



for validation iam using javascript code are as :
var d=document.getElementById('div-id');
var dd=d.getElementsByTagName('input');

for (i=0;i<dd.length;i++)
{
var j=dd;
if ( j.type=='checkbox' )
{
if ( j.checked == true )
{
return true;
break;

}



else ( j.checked == false )
{
alert("Pl Select Student to Move ");
return false;
}

}

}
its working but it asking for select everycheck box while its depends on user how many checkbox he can select.....
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: how to validate array check box in php

Post by tr0gd0rr »

Not sure what you are asking. Are you needing it to confirm that at least X boxes are checked instead of confirming whether all boxes are checked?
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: how to validate array check box in php

Post by manojsemwal1 »

yes i need that........
actually it is a list of student and iam using check box to allocate the student to their related center so we have to need select the student and allocate it in the center.
but for that i used to validate the first user select the center name and then select at least one student.
i used the script but in this script if i select a student again its asking for select student.

thanks
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: how to validate array check box in php

Post by daedalus__ »

if you edit your post to use code tags, ill help
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: how to validate array check box in php

Post by manojsemwal1 »

Which post do u want to edit..while the code is first post..............on the top
Post Reply