Welcome to WebmasterWorld Guest from 54.167.174.11

Forum Moderators: open

Message Too Old, No Replies

Checking the condition of 3 banks of radio buttons

How can it be done?

   
1:08 pm on Nov 11, 2003 (gmt 0)

10+ Year Member



Hi,

Hi I have an online form where users can select what options they would like of a "menu". For example an option asks would they like 2, or 3 courses? Then I have a bank of 5 radio buttons with different options for the first course, a bank of 5 for the second course and the same for the third course.

What I am trying to do, with little success, is if they selected 3 courses, and they haven't selected an option from each of the courses a javascript alert pops up.

Can anyone help?

Many Thanks.

4:48 am on Nov 12, 2003 (gmt 0)

10+ Year Member



This isn't quite what you asked for, but it might work for you. The banks of radio buttons are enabled/disabled based on the number of courses selected. Each bank is given a default value. Only 3 options per bank are listed here, but it should work with as many as you like. (tested IE6, Netscape 7, Opera 7.21 -- negative on NN4.x)

<html>
<head>
<title>My Page</title>
<script language="JavaScript" type="text/javascript">
<!--
function classNumber(c, r2, r3) {

if (c.value==1) {
for (var i = 0; i < r2.length; i++)
r2[i].disabled=true;
for (var i = 0; i < r3.length; i++)
r3[i].disabled=true;
}

else if (c.value==2) {
for (var i = 0; i < r2.length; i++)
r2[i].disabled=false;
for (var i = 0; i < r3.length; i++)
r3[i].disabled=true;
}

else if(c.value==3) {
for (var i = 0; i < r2.length; i++)
r2[i].disabled=false;
for (var i = 0; i < r3.length; i++)
r3[i].disabled=false;
}

}
//-->
</script>
</head>

<body>
<form name="myForm" action="YOUR_ACTION_HERE" method="post">
Select the number of courses
<select name="classes" onChange="javascript:classNumber(this, document.myForm.radio2, document.myForm.radio3);">
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
</select>
<br><br>
<input type="radio" name="radio1" value="option1" checked />Option 1
<input type="radio" name="radio1" value="option2" />Option 2
<input type="radio" name="radio1" value="option3" />Option 3
<br>
<input type="radio" name="radio2" value="option1" disabled="true" checked />Option 1
<input type="radio" name="radio2" value="option2" disabled="true" />Option 2
<input type="radio" name="radio2" value="option3" disabled="true" />Option 3
<br>
<input type="radio" name="radio3" value="option1" disabled="true" checked />Option 1
<input type="radio" name="radio3" value="option2" disabled="true" />Option 2
<input type="radio" name="radio3" value="option3" disabled="true" />Option 3
<br><br>
<input type="submit" value="submit">
</form>
</body>
</html>

9:47 am on Nov 12, 2003 (gmt 0)

10+ Year Member



Thanks mikegram, while it's not exactly what I was looking for, it gives me ideas and I can use it.

Many thanks for your time.