HTML control for radio button not work

yjchong514
yjchong514 used Ask the Experts™
on
Dear EE member,
I am a new learner for ASP.NET using vb.net to develop a simple quiz system.

I would like to store user input to radio button in each question to an array and compare it with the correct_answer array. Now, I try to retrieve the value store - but it 's not work.

Would appreciate for any help.

Regards,
yjchong
<%@ Page Language="VB" %>
<html>
<head>
<title>Test Question - ASPX</title>
<script language="VB" runat="server">

Sub buttonClick(Sender As Object, e As Eventargs)
 Dim index As Integer = 2
 Dim dataInput(index) As String 

 dataInput(0)=qone.value
 dataInput(1)=qtwo.value
 dataInput(2)=qthree.value

 For i=0 to 2
    Response.write dataInput(i) & "<BR>"
 Next i
End Sub
</script>
</head>
<body>
<form runat="Server">
<table>
<tr>
<td>
1. Select an animal which eats fish?
<input type="radio" id="qone" name="qone" value="1" runat="Server">Cat
<input type="radio" id="qone" name="qone" value="2" runat="Server">Elephant
<input type="radio" id="qone" name="qone" value="3" runat="Server">Lion
<input type="radio" id="qone" name="qone" value="4" runat="Server">Deer
</td>
</tr>

<tr>
<td>
2. Who is Bill Gate?
<input type="radio" id="qtwo" name="qtwo" value="1" runat="Server">IBM founder
<input type="radio" id="qtwo" name="qtwo" value="2" runat="Server">Sun founder
<input type="radio" id="qtwo" name="qtwo" value="3" runat="Server">Microsoft founder
<input type="radio" id="qtwo" name="qtwo" value="4" runat="Server">Acer founder
</td>
</tr>

<tr>
<td>
3. What is database?
<input type="radio" id="qthree" name="qthree" value="1" runat="Server">A storage
<input type="radio" id="qthree" name="qthree" value="2" runat="Server">A dust bin
<input type="radio" id="qthree" name="qthree" value="3" runat="Server">A fruit
<input type="radio" id="qthree" name="qthree" value="4" runat="Server">A telephone
</td>
</tr>

</table>
<br>
<input type="submit" name="button1" value="Complete and Send" OnServerClick="button_Click" runat="Server">
<input type="reset" name="button2" value="Start Over">
</form>
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Is it giving some error?

Author

Commented:
Compilation Error:
The ID 'qone' is already used by another control.

How to assign unique id to question one 's radio box? There are 4 options
and 3 questions, what is the better way?

I want to store it in an array and preferable using for loop to store the value into the array.

Any idea?

Author

Commented:
This one return less syntax error.

How to assign unique id to question one 's radio box? There are 4 options
and 3 questions, what is the better way?

I want to store it in an array and preferable using for loop to store the value into the array.

Any idea?
<%@ Page Language="VB" %>
<html>
<head>
<title>Test Question - ASPX</title>
<script language="VB" runat="server">

Sub button_Click(Sender As Object, e As Eventargs)
 Dim index As Integer = 2
 Dim dataInput(index) As String 

 dataInput(0)=qone.value
 'dataInput(1)=qtwo.value
 'dataInput(2)=qthree.value

 'For i=0 to 2
    Response.write(dataInput(0) & "<BR>")
 'Next i
End Sub
</script>
</head>
<body>
<form runat="Server">
<table>
<tr>
<td>
1. Select an animal which eats fish?
<input type="radio" id="qone" name="qone" value="1" runat="Server">Cat
<input type="radio" id="qone2" name="qone" value="2" runat="Server">Elephant
<input type="radio" id="qone3" name="qone" value="3" runat="Server">Lion
<input type="radio" id="qone4" name="qone" value="4" runat="Server">Deer
</td>
</tr>

<tr>
<td>
2. Who is Bill Gate?
<input type="radio" id="qtwo" name="qtwo" value="1" runat="Server">IBM founder
<input type="radio" id="qtwo2" name="qtwo" value="2" runat="Server">Sun founder
<input type="radio" id="qtwo3" name="qtwo" value="3" runat="Server">Microsoft founder
<input type="radio" id="qtwo4" name="qtwo" value="4" runat="Server">Acer founder
</td>
</tr>

<tr>
<td>
3. What is database?
<input type="radio" id="qthree" name="qthree" value="1" runat="Server">A storage
<input type="radio" id="qthree3" name="qthree" value="2" runat="Server">A dust bin
<input type="radio" id="qthree2" name="qthree" value="3" runat="Server">A fruit
<input type="radio" id="qthree4" name="qthree" value="4" runat="Server">A telephone
</td>
</tr>

</table>
<br>
<input type="submit" name="button1" value="Complete and Send" OnServerClick="button_Click" runat="Server">
<input type="reset" name="button2" value="Start Over">
</form>
</body>
</html>

Open in new window

Author

Commented:
I need to manipulate Multiple HTML Radio Buttons With The Same Name.
If user choose an option from radio box of question one, how to pass that value to an array element.

I don't want:
dataInput(0)=q1a.value
dataInput(1)=q1b.value
dataInput(2)=q1c.value
dataInput(3)=q1d.value

what I want:
dataInput(0) = correct option choosen from user

so that I can compare with correct ans in the other array.

I managed to solve it.
 dataInput(0)=request.form("q1")
 dataInput(1)=request.form("q2")
 dataInput(2)=request.form("q3")

 

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial