Im building a dating site in php and vould like to add some functionality with javascript. What I'm trying to achive here is when 'Any' checkbox is checked all the checkboxes in the 'p_hair[]' array should get checked and if you were to uncheck a checkbox in that array you would automatically uncheck 'Any'. Well here is my code and im gettign errors I dont know why (it has been couple of years since i last touched javascript to do forms)
<html>
<head>
<title> checkbox validate </title>
<script language="JavaScript">
<!--
// function accepts object and number of indexes in the array -1
function uncheckBox(o,i){
var objForm = document.forms[0];
var objName = o.name;
if(i == 0){
objForm.objName[0].checked = false;
} else {
for(var n=1;n<=i;n++){
objForm.objName[n].checked = true;
}
}
}
thanks to your insight i got my answer, your code is not exactly what I wanted but its nice to know you can use chekbox as a radio button What I initially wanted is to check as many as apply but do noct have 'Any' checkbox checked if not all checkboxes in the array were selected. Thanks again and here is a working version in case some one else is looking for it.
<html>
<head>
<title> checkbox validate </title>
<script language="JavaScript">
<!--
// function accepts object and number of indexes in the array -1
function uncheckBox(o,i){
var objForm = document.forms[0];
var objName = o.name;
if(i == 0){
o.form[o.name][0].checked = false;
} else {
for(var n=1;n<=i;n++){
o.form[o.name][n].checked = true;
}
}
}
//-->
</script>
</head>
Bookmarks