Forum Moderators: coopster

Message Too Old, No Replies

dealing with dynamic checkbox in php and javascript

want to know that if any of checkbox got checked or not

         

kadnan

5:31 am on Dec 28, 2002 (gmt 0)

10+ Year Member



i have developed a page in which dynamic categories are being shown with the help of a recursion function.i have also added a checkbox to delete a particular checkbox, the html source of file is something like.

<input type="Checkbox" name="C1" value="1">
cat1/<a href="javascript:editme(0,'cat1',1)">Edit</a><br>

<input type="Checkbox" name="C4" value="4">
----cat2/<a href="javascript:editme(1,'cat2',4)">Edit</a><br>

see the checkboxes name.i:e C1 then C4,means there is no sequence, and i coudn`t make it seuqntical due to recursive function and simple $count++ doesnt work for me
-is there anyway that I can check on client site that NONE of checkbox is CHECKED?

andreasfriedrich

8:53 am on Dec 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using JavaScript you could loop over the all elements of your form and do with each element whatever you need to do.

var myform = document.yourform; 
for(var i=0;i<myform.length;++i) {
if(myform.elements[i].type=='checkbox') {
myform.elements[i].checked=false;
}
}

Beware that despite such client side checks you always need to check the supplied data on the server again.

Andreas

kadnan

10:14 am on Dec 30, 2002 (gmt 0)

10+ Year Member



thanx
what i mean that i want to detect UNCHECKED boxes on client side
if all boxes are Unchecked then show an alert
i didn`t mean that I want to make checkboxes UNCHECKED
-adnan

andreasfriedrich

10:51 am on Dec 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Modifying me example to do exactly what you want should be fairly easy.

Andreas