I have a form with a few radio button selections.
Here is what I wouuld like to do.
Questions 1 & 2 are required. However, if in question #1 Q1= A or Q1 =B then another radio selection poplulates and dislpays the three options for Q1a. An option must be selected from Q1a if A or B was selected in Q1. Of course if C is selected in Q1 then the options for Q1a are not displayed or requried.
<FORM>
<input type='radio' name='Q1' value='A' ID='Q1' >
<input type='radio' name='Q1' value='B' ID='Q1' >
<input type='radio' name='Q1' value='C' ID='Q1' >
<input type='radio' name='Q1a' value='A' ID='Q1' >
<input type='radio' name='Q1a' value='B' ID='Q1' >
<input type='radio' name='Q1a' value='C' ID='Q1' >
<input type='radio' name='Q2' value='A' ID='Q2' >
<input type='radio' name='Q2' value='B' ID='Q2' >
<input type='radio' name='Q2' value='C' ID='Q2' >
</FORM>
Here is my script that does partially work however I need to include some type of IF statement validating the Q1a radio buttons if Q1 = A or B.
function CheckResponse()
{
var radio_choice1 = false;
for (counter = 0; counter < Form1.Q1.length; counter++)
{
if (Form1.Q1[counter].checked
)
radio_choice1 = true;
}
if (!radio_choice1)
{
alert("Please answer question 1.")
document.Form1.Q1.focus();
return (false);
}
var radio_choice1a = false;
for (counter = 0; counter < Form1.Q1a.length; counter++)
{
if (Form1.Q1a[counter].checke
d)
radio_choice1a = true;
}
if (!radio_choice1a)
{
alert("Please answer question 1a.")
document.Form1.Q1a.focus()
;
return (false);
}
var radio_choice2 = false;
for (counter = 0; counter < Form1.Q2.length; counter++)
{
if (Form1.Q2[counter].checked
)
radio_choice2 = true;
}
if (!radio_choice2)
{
alert("Please answer question 2.")
document.Form1.Q2.focus();
return (false);
}
return (true);
}
Start Free Trial