Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get id of selected radio button asp

Status
Not open for further replies.

princesszea

Technical User
Aug 11, 2008
33
GB
Basically I have dynamic radio buttons and I am trying to display a dropdown based on the selection of the radio button. Currently I have 4 radio buttons so when I try and get the ID of the selected radio button I get the ID for all the radio buttons (1,2,3.4) instead of the ID of the selected one so if the second radio button was selected I should only get ID 2.
My code for that section is below without the new dropdown I am trying go create as I need to pass the value of the ID into a stored procedure.

This is the code I currently have
Code:
<form name="form1" method="Post" action="Page.asp?v=<%=V%>">

<table cellpadding="0" cellspacing="0" border="0" class="DarkBoldText" width="900">
<tr><td width="50">V:</td><td width="590" class="NormalText"><%=V%></td><td><input type="button" value="Back" onclick="javascript:history.back();"></td></tr>

</table>

<table cellpadding="0" cellspacing="0" border="0" class="NormalText" width="900">
<tr height="10"><td colspan="3"></td></tr>
<tr>
</tr>
<tr height="5"><td colspan="3"></td></tr>

<%

if Status 1 then
	QCount=0
	SQLString="uspQuery_GetQuestions " & 1
	set rs2=adoConn.Execute(SQLString)
	do until rs2.eof
		QCount=QCount + 1
		if Status = "1" then
			if len(Request.Form("QQuestion" & QCount)) > 0 or len(Request.Form("QueryTypes" & QCount)) > 0 then
				aQ(QCount)="1"%>
				<tr bgcolor="#FFFFF0" height=25 valign="bottom" >
				<td valign="bottom"><%=Replace(rs2("text"), "/", "'")%></td><td></td><td></td><td></td></tr>
				<tr bgcolor="#FFFFF0">
				<td valign="top">
				<%set rs3=adoConn.Execute("storedprocedure " & Status)%>
					<SELECT id="Types<%=QCount%>" name="Types<%=QCount%>" class="NormalText">
					<OPTION value"0">Select a query...</OPTION>
					
				<%
				do until rs3.eof%>
					<OPTION value="<%=rs3("ID")%>"><%=Replace(rs3("text"), "/", "'")%></OPTION>
					<%rs3.movenext
				loop%>
				</SELECT></td>
			
			<%end if
			
		else%>
			<tr bgcolor="#FFFFF0" height=25>
			<td><%=Replace(rs2("text"), "/", "'")%></td><td></td><td></td><td><INPUT type="radio" id="Question<%=rs2("Id")%>" name="Question<%=rs2("Id")%>" value="1" class="NormalText" i></td>
			
			<script type="text/javascript">radioButtons()</script>
				
			</tr>
			<tr height="7"><td colspan="3"></td></tr>
		<%end if
		rs2.movenext
	loop
end if
<tr><td colspan=4 align="right"><INPUT type="button" value="Submit2" id=button2 name=button2 onclick="javascript:Query()" style="Cursor:hand"></td></tr>

I have a another page that contains my javascript


Code:
var radios = new Array();
 
function radioButtons() {
  var inputs = document.getElementsByTagName('input');
  var r = document.getElementsByTagName("input");
  var selected="";
  for (var i = 0; i < inputs.length; ++i) {
    if (inputs[i].type == "radio") {
      radios[radios.length] = inputs[i];
      radios[radios.length - 1].onclick = function() {  
        for (var j = 0; j < radios.length; ++j)
        radios[j].checked = false;
 
        this.checked = true;
      }
    }
  }


and this is the line of interest in my asp page

Code:
<td><INPUT type="radio" id="QQuestion<%=rs2("Id")%>" name="QQuestion<%=rs2("Id")%>" value="1" class="NormalText" ></td>


Thanks
 
Hi Princesszea
With apologies for looking at your code samples very quickly so I may have missed something, the problem lies in having > 1 radio button appearing to be checked. Are these the only group of radio's on the page? Are they uniquely named? I'm not certain what your second code fragement is achieving - why do the radio's have to be cleared and reset?
HTH, Linnet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top