I have a page that contains a set of options, some are checkboxes, some are radio buttons, and I need to guarantee at least one of each is selected. So far I have a list that contains radio buttons with value=group1 and some checkboxes with value = sl_$dbid (where $dbid is created in PHP and resolves to sl_1, sl_2, sl_3 etc.)
I need to confirm that the a radio button is selected, and at least one of the checkboxes is selected.
I have some javascript I put together, which doesn't yet work, but if anyone can offer some advice it would be appreciated:
Code: Select all
function ValidateDBSelect(){
//Radio Button
u=''
for (a=0;a<document.forms[0].group1.length;a++) {
if (document.forms[0].group1[a].checked) {
user_input = document.forms[0].group1[a].value;
u++
}
}
if ((u.value==null)||(u.value==""||u.value<1)){
alert("Please Select a Radio Button")
u.focus()
return false
}
//Check Box
v=''
for (b=0;b<document.forms[0].group1.length;b++) {
if (document.forms[0].sl_b.checked) {
user_input = document.forms[0].sl_b.value
v++
}
}
if ((v.value==null)||(v.value==""||v.value<1)){
alert("Please Select at least one Slave Database")
v.focus()
return false
}
}