p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Help with radio buttons problem


Message #1 by "Irene" <lawirene88@y...> on Tue, 11 Dec 2001 17:23:46
The only way to make you radio buttons mutually exclusive is to give them
the same name.

Your radio buttons are getting different names because of the following
code:

<input type=radio name="&radiobuttonvar&  "value=A>

Might want to put a space before the value and I think you will be set.

Steve

-----Original Message-----
From: Vince Kavanagh [mailto:vince@6...]
Sent: Tuesday, December 11, 2001 2:44 PM
To: Code Clinic
Subject: [proasp_codeclinic] RE: Help with radio buttons problem


Try something like this:

<html>
<body>
<head>
<script language="JavaScript">
<!--
function radioCheck(radio) {
  var radioGroup = document.options.hello;
  for (var i = 0; i < radioGroup.length; i++)
    if (radioGroup[i] != radio.checked)
      radioGroup[i].checked = false;
  return radio.checked;
}
//-->
</script>
</head>
<Form name=frmRadio>
<input type=radio name=hello value=hello1 onclick=return
radioCheck(this);>Hello1
<input type=radio name=hello value=hello2 onclick=return
radioCheck(this);>Hello2
<input type=radio name=hello value=hello3 onclick=return
radioCheck(this);>Hello3
</body>
</html>

Regards,

Vince.

-----Original Message-----
From: Irene [mailto:lawirene88@y...]
Sent: 11 December 2001 17:24
To: Code Clinic
Subject: [proasp_codeclinic] Help with radio buttons problem


Hi everybody,

I'm using ASP to generate a table with radio buttons. I want to only let
the user pick one option, that's why i used radio buttons. However, when I
generate the table with the radio buttons using ASP, I find that I'm able
to choose multiple options. Can anyone help me solve this problem?
Actually this is an online test, so the user should only be able to choose
one answer for each question.

<% ......processing for retrieving information from database.......

TestQuestionID = objRs("QuestionID")
TestQuestion = objRs("Question")
TestOptionA = objRs("OptionA")
TestOptionB = objRs("OptionB")
TestOptionC = objRs("OptionC")
TestOptionD = objRs("OptionD")

IF not objRs.EOF then
Response.Write "<TABLE BORDER=""1"" CELLSPACING=""3"" CELLPADING=""3"">" &_
				 "<TR>" &_
				 "	<TH>Test Question ID </TH>" &_
				 "	<TH>Test Question</TH>" &_
				 "	<TH>Option A</TH>" &_
				 "	<TH>Option B</TH>" &_
				 "	<TH>Option C</TH>" &_
				 "	<TH>Option D</TH>" &_
				 "</TR>"
				 radiobuttonvar = 0
				 'objRs.Move 1
				 Do While Not objRs.EOF

Response.Write  "<TR ALIGN=CENTER>	<TD>" & objRs("TestQuestionID")
&"</FONT></td>	<TD><font color="&qfontcolour&" size="&qfontsize&">"&objRs
("TestQuestion") & "</td>	<TD>"& "<input type=radio name="
&radiobuttonvar&  "value=A>" &objRs("TestOptionA") &"</td>	<TD>"
& "<input type=radio name= "&radiobuttonvar& "value=B>"&objRs
("TestOptionB") &"</td>	<TD>" & "<input type=radio
name= "&radiobuttonvar& "value=C>"&objRs("TestOptionC") &"</td>	<TD>"
& "<input type=radio name= "&radiobuttonvar& "value=D>"&objRs
("TestOptionD") &"</td></tr>"

				objRs.MoveNext
				radiobuttonvar = radiobuttonvar+1
			Loop
			Response.Write "</TABLE>"
			else
				Response.Write "No questions "
			End If
			objRs.Close
		%>
Thanks very much
$subst('Email.Unsub').


$subst('Email.Unsub').


  Return to Index