scottie_24
asked on
Script to force a radio button selection...
I'm querying a database with ASP that lists selections with radio buttons, and it lists anywhere from zero to 30 records. I have this code to force a selection before going to the next page:
<script language="JavaScript">
function checkForm(theForm) {
msg = "";
qTrain = theForm.schedule_chosen;
qCheck = false;
for(i=0;i<qTrain.length;i+ +){
if(qTrain[i].checked==true ){
qCheck = true;
}
}
if (qCheck == false) {
msg += "You must choose a shift";
}
if (msg>"") {
alert (""+msg);
return false
}
}
</script>
It works just fine when I have more than 1 record listed, but when there is only 1 listed it keeps prompting the user with "You must choose a shift". Any idea what's wrong in this script? If it helps, this is my code for the radio buttons:
Response.Write "<tr><td><input type='radio' name='schedule_chosen' value='"&rs2("num")&"'>" & rs2("11_26") & "</td></tr>"
Any help is much appreciated.
Scottie
<script language="JavaScript">
function checkForm(theForm) {
msg = "";
qTrain = theForm.schedule_chosen;
qCheck = false;
for(i=0;i<qTrain.length;i+
if(qTrain[i].checked==true
qCheck = true;
}
}
if (qCheck == false) {
msg += "You must choose a shift";
}
if (msg>"") {
alert (""+msg);
return false
}
}
</script>
It works just fine when I have more than 1 record listed, but when there is only 1 listed it keeps prompting the user with "You must choose a shift". Any idea what's wrong in this script? If it helps, this is my code for the radio buttons:
Response.Write "<tr><td><input type='radio' name='schedule_chosen' value='"&rs2("num")&"'>" & rs2("11_26") & "</td></tr>"
Any help is much appreciated.
Scottie
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm, thanks.
<script language="JavaScript">
function checkForm(theForm) {
var msg = null;
qTrain = theForm.schedule_chosen;
qCheck = false;
for(i=0;i<qTrain.length;i+
if(qTrain[i].checked==true
qCheck = true;
}
}
if (qCheck == false) {
msg += "You must choose a shift";
}
if (msg) {
alert (""+msg);
return false
}
}
</script>