burnsj2
asked on
Javascript checkbox problem
I have the following javascript to make checkboxes act like radio boxes (allow only 1 to be checked) which doesn't work. The condvals array contains the variable names:
function checkBoxValidate(cb) {
var condvals=new Array("document.form1.cond itioncance rBladder", "document. form1.cond itioncance rBrain","d ocument.fo rm1.condit ioncancerB reast","do cument.for m1.conditi oncancerCo lorectal", "document. form1.cond itioncance rEndometri al","docum ent.form1. conditionc ancerEsoph ageal","do cument.for m1.conditi oncancerKi dney","doc ument.form 1.conditio ncancerLeu kemia","do cument.for m1.conditi oncancerLu ng","docum ent.form1. conditionc ancerMelan oma","docu ment.form1 .condition cancerNonh odgkinsLym phoma","do cument.for m1.conditi oncancerPa ncreatic", "document. form1.cond itioncance rProstate" ,"document .form1.con ditioncanc erStomach" ,"document .form1.con ditioncanc erThyroid" ,"document .form1.con ditioncanc erOther");
for (j = 0; j < 16; j++) {
if (eval(condvals[j] +".checked") == true) {
condvals[j].checked = false;
if (j == cb) {
condvals[j].checked = true;
}
}
}
}
The input tags have
onClick="javascript:checkB oxValidate (0)"
onClick="javascript:checkB oxValidate (1)"
etc.
It produces no errors but doesn't work.
Thanks
function checkBoxValidate(cb) {
var condvals=new Array("document.form1.cond
for (j = 0; j < 16; j++) {
if (eval(condvals[j] +".checked") == true) {
condvals[j].checked = false;
if (j == cb) {
condvals[j].checked = true;
}
}
}
}
The input tags have
onClick="javascript:checkB
onClick="javascript:checkB
etc.
It produces no errors but doesn't work.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works great, thanks!
function checkBoxValidate(cb) {
var condvals=new Array("document.form1.cond
oClicked = eval(condvals[cb])
for (j = 0; j < 16; j++) {
oJ = eval(condvals[j]);
oJ.checked = ( (j == cb) && oClicked.checked );
}
}