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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio buttons won't hold state 1

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
I have a web form with two radio buttons from which the user makes a selection and gets a different set of choices. These work fine except that the selected radio button won't maintain its checked state after the submit button is clicked (too bad there isn't an onclick event so that I could get rid of the button). Here is the basic code I have now:


<tr>
<td colspan='2' align='center'>
<input type='radio' name='radSelectBy' value='State' ><b>Select State</b>
<br>
<input type='radio' name='radSelectBy' value='Region' ><b>Select by Region</b>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<input type='submit' value='Submit'></input>
</td>
</tr>
<%
Session("Sel") = Request.Form("radSelectBy")%>
<tr>
<td align='center'>
<%= Session("Sel") %>
</td>
<td align='center'>
<%
If (Session("Sel") = "Region") Then
%>
Select by Region
<%
End If
If (Session("Sel") = "State") Then
%>
Select by State
<%
End If
%>
</td>
</tr>

I have tried using the session variable to create an If statement that selects a checked version of one radio button and an unchecked version of the other, and it worked but only if the screen is refreshed (the processing in the last If statement works fine) and that pops up a message box saying that the information must be retransmitted and did I really want to do it)

How can I make the checkboxes maintain state?
 
The session variable is being created after the radio buttons are created so never interact.

Try this (call the file cbtest.asp)

Code:
<form method="post" action="cbtest.asp">
<table>
<tr>
  <td colspan='2' align='center'><input type='radio' name='radSelectBy' value='State' <%if Request.Form("radSelectBy")="State" then response.write("checked")%> onclick="this.form.submit()">
    <b>Select State</b> <br>
    <input type='radio' name='radSelectBy' value='Region' <%if Request.Form("radSelectBy")="Region" then response.write("checked")%> onclick="this.form.submit()">
    <b>Select by Region</b> </td>
</tr>
</table>
</form>

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top