AllExperts > Experts 
Search      

Active Server Pages Programming (ASP)

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Srini Nagarajan
Expertise
I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience
Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.
 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > storing radio button values in an array

Topic: Active Server Pages Programming (ASP)



Expert: Srini Nagarajan
Date: 3/19/2008
Subject: storing radio button values in an array

Question
i retrieve 3 fields from a db.
question1        option1      option2
question2        option2      option2

question - text box option1 - radio option2 - radio
i display all the records in a page
if option1 is clicked,option1_ctr of the particular row should be incremented

here is the code:
<%
Dim Conn 'Holds the Database Connection Object
Dim RS 'Holds the recordset for the records in the database
Dim mySQL1 'Holds the SQL query to query the database
Dim execSQL
Dim ques
Dim opt1
Dim opt2
Dim y_ctr
Dim n_ctr
Dim theform


Set Conn = Server.CreateObject("ADODB.Connection")

Conn.ConnectionString = "DSN=pollz"
Conn.Open


mySQL = "SELECT * FROM pollz"


Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open mySQL, Conn,3,3

rcount=rs.recordcount

myArraySize=rcount
Dim rbArr()
Redim s(rcount,2)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<SCRIPT language="JavaScript">

function testButton (form){
var y_ctr;
var n_ctr;
var quest;
var s =[];
y_ctr=<%=yes_ctr%>
n_ctr=<%=no_ctr%>


alert(y_ctr);
alert(n_ctr);
if (form.ans[0].checked)
{
y_ctr=y_ctr+1;
n_ctr=n_ctr;
document.array1.hid_code_y.value=y_ctr;
document.array1.hid_code_n.value=n_ctr;
alert(document.array1.hid_code_y.value)
alert(document.array1.hid_code_n.value)
}
else
{
n_ctr=n_ctr+1;
y_ctr=y_ctr;
document.array1.hid_code_n.value=n_ctr;
document.array1.hid_code_y.value=y_ctr;
alert(document.array1.hid_code_y.value)
alert(document.array1.hid_code_n.value)
}

document.array1.submit();
}
</script>
</head>

<body>
<%
rs.movefirst
clr=1
ques=request.Form("quess")

Do while Not rs.eof %>

<form name='array1' method='post' action='final.asp'>
<table valign='top' border=1 align=center width='80%' cellpadding=0 cellspacing=0>
<tr><td width='70%'> <%= rs("question")%> </td>

<td width='6%'><input type='hidden' name='quess' value="" <%= rs("question")%>""></td>
<td width='6%'><input type='radio' onClick='testButton(this.form)' name='ans' value= <%= rs("option1")%></td>
<td width='6%'><input type='radio' onClick='testButton(this.form)' name='ans' value=<%= rs("option2")%> </td>
</tr>

</table>
<input type='hidden' name='hid_code_y'>
<input type='hidden' name='hid_code_n'>
<input type="hidden" name="insrow" value= "1">
</form>

<%
yes_ctr=rs("option1_ctr")
no_ctr=rs("option2_ctr")



rs.movenext
i=i+1
j=0

Loop
%>
<%If request.Form("insrow")="1" Then
y_ctr=request.Form("hid_code_y")
n_ctr=request.Form("hid_code_n")
ques=request.Form("quess")
MYSQL1 = "UPDATE pollz SET option1_ctr = " & y_ctr &", option2_ctr =" & n_ctr &"  where question='" & ques & "'"
response.write mysql1
Conn.execute(mysql1)
End If
RS.Close
Set RS = Nothing
Set Conn = Nothing

%>


</body>
</html>


Answer
Hi

What exactly you want the output? why do you want in array?
What is the alert is displaying for you.  

my suggession is create a hidden variable and add all the question id and answer with comma delimited and read the hidden variable in you code to update.  the output of the hidden variable should

q1^2,q2^1,q3^1....

means
question1 answer is option2
question2 answer is option1
question3 answer is option1...

using instr and split you should be able to retrieve the value in your ASP side

Thanks

-Srini

View Follow-Ups    Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.