Click to See Complete Forum and Search --> : How to Request the result from ASP if Users check d checkbox.


JohnJava
02-17-2004, 11:22 PM
Hi all, I want to know how to produce the result in ASP, since I don't have any idea in this part.
What I want ASP to do to me is to get the no. of checkbox checked, for instance, if the user check the checkbox no.2 and chekbox number no.3 in Stage 1(Question 1), then the ASP will calculate (answer=2*3*1) where no.2 is checkbox no.2, 3 is checkbox no.3, and no.1 is Question no.1 or Stage 1. Lastly, I want it reply the total to HTML. Please Help me...

Below is example coding that I created in HTML
<html>

<head>
<title>Survey</title>

<script type="text/javascript">

var nq = 2 //input number of questions
var nc = 3 //input the number of checkboxes on a question
var x
function check(a)
{ c = new Array()
for(i=0; i<nc; i++){
c[i] = document.forms[0].elements[a.name][i].checked
if(c[i] == true){x = i}}

n = new Array()
for(j=0; j<nq*nc; j++){
n[j] = document.forms[0].elements[j].name
for (i=0; i<nc; i++){
if (i==x){document.forms[0].elements[n[j]][i].disabled = true}}}}

function refresh()
{location.reload()}

</script>
</head>

<body>
<form action ="process.asp" id="process" name="process">

<b>Stage 1</b><table border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr><td width="100%"><input name="q0" type="checkbox" onclick="check(this)" value="ON"></td></tr>
<tr><td width="100%"><input name="q0" type="checkbox" onclick="check(this)" value="ON"></td></tr>
<tr> <td width="100%"><input name="q0" type="checkbox" onclick="check(this)" value="ON"></td></tr>
</table>
<p><br>

<b>Stage 2<br>&nbsp;</b>
<table border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
<tr><td width="100%"><input name="q1" type="checkbox" onclick="check(this)" value="ON"></td></tr>
<tr><td width="100%"><input name="q1" type="checkbox" onclick="check(this)" value="ON"></td></tr>
<tr><td width="100%"><input name="q1" type="checkbox" onclick="check(this)" value="ON"></td></tr>
</table>

<input type="reset" value="Reset" name="cmdSubmit" onclick="refresh()">
<input type="submit" value="Submit" name="cmdSubmit">

</form>
</body>

</html>

buntine
02-17-2004, 11:30 PM
This should tell you how many checkboxes have been cheakc for each question..


dim q1, q2
dim answer1, answer2
dim i

q1 = UBound(Split(request.form("q1"), ","))
q2 = UBound(Split(request.form("q2"), ","))

response.write("Boxes checked for qestion 1: " & q1 & vbCrLf)
response.write("Boxes check for question 2: " & q2 & vbCrLf)


In your form element, set the method attribute to "post".

For the answer, add the following.

for i = 0 to q1
answer1 = answer1 * CInt(Split(Request.form("q1"), ",")(i))
next

for i = 0 to q2
answer2 = answer2 * CInt(Split(Request.form("q2"), ",")(i))
next

response.write("Answer one: " & answer1 & vbCrLf)
response.write("Answer two: " & answer2 & vbCrLf)



Regards,
Andrew Buntine

JohnJava
02-17-2004, 11:46 PM
Thanks, but where should i put this code, is it in ASP file or HTML?

buntine
02-17-2004, 11:52 PM
All ASP code must be placed inside a file with a .asp extension. So, place the code inside process.asp

When the form is submitted, the data will be sent to the server and process.asp will process the info and output the correct results to the browser.

Regards.

JohnJava
02-18-2004, 12:08 AM
Thanks so much, You are the BEST, the GOOD, the SMART. I hope you can guide me when i need.

buntine
02-18-2004, 12:13 AM
Hey, thanks buddy..

I always try my hardest. I am one of those people who learn from helping others.