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!

ASP server side radio button problem

Status
Not open for further replies.

manvee1

Programmer
Jul 17, 2002
22
US
Problem.

I have this html on my client:

<A>1. How Long does it take the earth to orbit the sun?</A><BR>
<INPUT type="radio" name="radiobutton1" value="365">A) 365 days<BR>
<INPUT type="radio" name="radiobutton1" value="364">B) 364 days Mth<BR>
<INPUT type="radio" name="radiobutton1" value="300">C) 300 days<BR>
<INPUT type="radio" name="radiobutton1" value="500">D) 500 days<BR>
<BR>


And I have this ASP on my server.

Dim radioB1, radioB2, radioB3, radioB4, radioB5
Dim questCount
questCount = 0

radioB1 = request.form("radiobutton1")

if radioB1 = "365" then
questCount = questCount + 1
end if

'Write out the result
Response.Write("<b>You answered " & questCount & " Questions Correct </b>" & "<br>")


the problem is thatmy variable fo rmy radio button 'questCount' is always 0.

How can I get the value of the radiobutton that was clicked?
thanks
manvee1

 
I think each radio button should have a different name.

John Borges
 
Hi There,

Please specify your Question Correctly.

do you want to

1. calculate the no of questions answered correctly.
or
2. the value of the radiobutton that was clicked

if your ans is 2 then here is the code :
========================================
try this code :

<A>1. How Long does it take the earth to orbit the sun?</A><BR>
<INPUT type="radio" name="radiobutton1" value="365-1">A) 365 days<BR>
<INPUT type="radio" name="radiobutton1" value="364-2">B) 364 days Mth<BR>
<INPUT type="radio" name="radiobutton1" value="300-3">C) 300 days<BR>
<INPUT type="radio" name="radiobutton1" value="500-4">D) 500 days<BR>
<BR>


Asp Code:


Dim radioa
Dim questCount

radioa = split(request.form("radiobutton1"), "-")


'Write out the result
Response.Write("You answered "& radioa(1) &" option which is :"& radioa(0))


 
Thanks for your help


Jbpez...i think i need the same name so as to group them up. where u can only have 1 radio selected for each answer.


oops4me... I am trying to calculate the no of questions answered correctly. but in order to do so i also need to get the value of the radiobutton that was clicked.


i have 5 questions of which u have 4 choices a - d for each question. Each of the choices is a group of radiobuttons.
question 1 choices is the group of radiobutton1 and question 2 choices is the group of radiobutton2 etc...

the user answers the all 5 multiple choice questions and the server is supposed to count how many ?s were answered correctly. and spit result back, which is what my counter should be counting.



radiob1 = CInt(request.form("radiobutton1"))
radiob2 = Request.Form("radiobutton2")
radiob3 = CInt(Request.Form("radiobutton3"))
radiob4 = Request.Form("radiobutton4")

at this point radiob1 to 4 are all = to 0 and not the values selected at client and thats the problem...


i go on to check...

if radiob1 = "365" then
questCount = questCount + 1
end if

if radiob2 = 'asdf' Then
questCount = questCount + 1
End If

if radiob3 = '2' Then
questCount = questCount + 1
End if

...etc




radiob1 = request.form("radiobutton1") ...is never equal to the value clicked in the 1st question at the client '365'

radio1 is always 0. The asp condition of ...if radiob1 = "365" returns false no matter what i click





 
From what I see you have a loop trying to count how many questions are answered and you have radiobutton1-radiobutton4 grouped on the pages I would assume. I would do one of thwo things

response.write the radiob1 and see what comes out. so you can test for the right answer. if it's 365 then you know its correct. also I noticed you're using request.form. trying using request without .form or .querystring it might pick it up correctly.

-KS
 
Response.Write(radiob1 & "gsgsg") returned only the text gsgsg ie. radiob1 was blank

request.form, request and request.querystring did not change anything. radiob1 is still blank

i even tried removing <%option explicit%> and all the variable declarations and that did not work
 
so basically what's happening is that the information is not being passed to your radiob1 variable. take a look at what happens when u do a request.form("radiobutton1") are you sure that it's correct. try to get to the smaller part of the problem if it's just where the info is not passed to variable you now know where to look.
 
I figured the problem

Ther was no problem with the code, the web server (web samba free web hosting "websamba.com") was the problem.

i moved my code to another server and it works fine without changing the code.

i spent 1 hrs writing this code and a total of 2 days debugging how stressful....



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top