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!

Radio Button

Status
Not open for further replies.

JustWondering

Technical User
Jun 28, 2003
57
US
Hi,

I have a group of radio buttons in page1. When user click submit, if one of the button is not selected, I want to display a msg to tell user must select one to move on.

I have some thinf like this but it didn't work (let user go to next page)

<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 1<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 2<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 3<br>

If Request(&quot;rdbutton&quot;) then problem=true
If problem=true then
Session(&quot;errMsg&quot;)=&quot;Please select one&quot;
redirect to same page
End if.

What's wrong with my code?
 
this must help:

<input type=&quot;radio&quot; name=&quot;rdbutton&quot; checked>Radio 1<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 2<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 3<br>


this will ensure that the user selects atleast one option...

Known is handfull, Unknown is worldfull
 
I found the error, something to do with my session(&quot;errMsg&quot;).

How can make a popup instead of session?
 
My boss want to make sure user pays attention to what button he select so...default value is not an option for me.
 
Just Wondering,

ON YOUR FORM PAGE:
------------------
You are missing something from your radio buttons - a value for each one!

Code:
<input type=&quot;radio&quot; name=&quot;rdbutton&quot; value=&quot;1&quot;>Radio 1<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot; value=&quot;2&quot;>Radio 2<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot; value=&quot;3&quot;>Radio 3<br>

-------------------------------
ON YOUR PROCESSING SCRIPT:

Code:
<%
Option Explicit

Dim strRadioChoice
strRadioChoice = Request.Form(&quot;rdbutton&quot;)
'or use: strRadioChoice = Request.Querystring(&quot;rdbutton&quot;)

If strRadioChoice = &quot;&quot; Then
    'No button selected:
    Response.Write(&quot;<html><body>You need to select an option.<br><a href=&quot;&quot;javascript:history.go(-1)&quot;&quot;>Back</a></body></html>&quot;)
Else
    'One was selected:
    Response.Write(&quot;<html><body>Option &quot; & strRadioChoice & &quot; was selected.</body></html>&quot;
End If
%>


Dave Mc Donald
 
Thank you.

How can I pass the text item of the radio button to the next page?

I try:

Session(&quot;rd&quot;)=Request(&quot;rdbutton&quot;)

If i select 1 button, On the next page I got
Session(&quot;rd&quot;)=ON.

I want the text of that RD not ON or OFF
 
Sorry...my bad...I must set value=&quot;something&quot; to pass along.
 
o.k there is another way by using javascript (i love it):
<input type=&quot;radio&quot; name=&quot;rdbutton&quot; checked>Radio 1<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 2<br>
<input type=&quot;radio&quot; name=&quot;rdbutton&quot;>Radio 3<br>


<script>
function CheckChecked()
{
sel=0
len=document.getElementsByName(&quot;rdbutton&quot;).length
for(i=0;i<len;i++)
{
if(document.getElementsByName(&quot;rdbutton&quot;).checked==true)
{
sel++
}
}
if(sel==0)
{
alert(&quot;Please select atleast one option box.&quot;)
}
}
</script>


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top