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!

Calculate radio buttons in form 1

Status
Not open for further replies.

enzobanzai

Technical User
Jun 24, 2004
16
AU
Hi

I am developing a page that has a form on it with 10 questions. Each
question has a 1 to 10 radio button option for the user to choose.

The forms actions posts this info to the results page which displays the
resluts using the request.Form method.

How do I add up or calculate the total results to give the user a score?

Can this be done?

Here is my page (testing). Please go ahead and try it and you will see what
I am trying to do.


I want to add together all the results and display this in the "score"

Thanks
Enzo
 
do you actually store the rate number in a db? you could just do a sum on the answers...

or just

for each element in request.form
if left(element,x) = "scoreme" then ' whatever, some naming convention to determine it's something it needs to add into the score value
MyScore = MyScore + Cint(request(element))
End If
next

response.write myscore

[thumbsup2]DreX
aKa - Robert
 
just looked at your source, could you add say "radio" as a prefix to the "one" "two" , so the loop will work .. OR you can just array up a list of fields to count :

tally = split("one,two,three,....",",")

for each item in tally
myscore = myscore + cint(request(tally))
next
response.write myscore

[thumbsup2]DreX
aKa - Robert
 
first reply requires no modification if you add a new scoring item...

second reply you will need to update the array to include the new item in counting/score

[thumbsup2]DreX
aKa - Robert
 
Hello DreXor

Thanks for the quick reply.

Im situated in Australia so usually I port a question on a forum then wait till the next morning to get a reply due to the time difference.

But anyway.

I am very new to this so I do not fully understand the first post but I definatley want to give it a try.

I am not storing the results in a db.

Is there any way you go show me how to get this up and running using my example and radio button names.

I dont understand "for each element in request.form" and what comes after that.

Even if you just show me an example using say the first three questions (one, two, three)

If I have to change the names of the radio button groups to eg.radioOne, radioTwo then I can.

Thanks again
Enzo
 
just for ease of headaches, rname all the radio name="one" etc to name="radioone" etc..

copy paste this code block into your receiving ASP page for the form, and it must be ASP in order to allow this code to run

Code:
<%
for each element in request.form
  if left(element,x) = "scoreme" then ' whatever, some naming convention to determine it's something it needs to add into the score value
    MyScore = MyScore + Cint(request(element))
  End If
next
%>
<script language="javascript">
  alert("your score was <%=myscore%>");
</script>

paste this code anywhere between <BODY> and </BODY>
preferably right after the initial body tag.

[thumbsup2]DreX
aKa - Robert
 
ack
correction, too quick on the submit button[cannon]


just for ease of headaches, rename all the radio name="one" etc to name="radioone" etc.. as you noted in your reply

copy paste this code block into your receiving ASP (financialTestResults.asp) page for the form

Code:
<%
myscore=0
for each element in request.form
  if left(element,5) = "radio" then 
    MyScore = MyScore + Cint(request(element))
  End If
next
%>
<script language="javascript">
  alert("your score was <%=myscore%>");
</script>
paste this code anywhere between <BODY> and </BODY>
preferably right after the initial body tag.


[thumbsup2]DreX
aKa - Robert
 
Hey Mate

Have updated the page ( described.

You can see the code and where I placed your code.

Still not adding up.

I havent renmaed the radio buttons on the prev page yet bu that should not make a difference to this working should it?

What I did want is for the score to display on the page (financialTestResults.asp) in the space next to score. Not in a pop up.

Is this possible?

Hey thanks for the help I realy appreciate it.

This is my first time on this forum.

Will come back and try to answer others questions if I can one day soon.

Enzo
 
yeah renaming the radios did affect this page, you'll need to name them back, in the meantime let me try and figure something up for you .. if possible, can you post the code from the results page so i can have a better idea of what i'm working with.

[thumbsup2]DreX
aKa - Robert
 
<html>
<head>
<title>Fitzpatrick's Australia - Financial Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cssStyles/fitzStyle.css" rel="stylesheet" type="text/css">
<link href="cssStyles/ltd.css" rel="stylesheet" type="text/css">

</head>

<body bgcolor="#DDDAC7" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="765" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="borderPage">
<tr align="right" valign="top" bgcolor="#FFFFFF">
<td height="100" colspan="2">
<table width="765" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="270"><span class="black18"><a name="top"></a></span><img src="images/headerLogo.gif" width="270" height="100"></td>
<td width="495" align="right"><img src="images/headerPic_2.jpg" width="495" height="100"></td>
</tr>
</table>
</td>
</tr>
<tr align="left" valign="top">
<td height="172" colspan="2" class="bannerStroke"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="142" align="left" valign="top" class="leftPicLine"><img src="images/banners/5.jpg" width="142" height="172"></td>
<td width="623" align="left" valign="top"><img src="images/banners/5%20_large.jpg" width="623" height="172"></td>
</tr>
</table></td>
</tr>
<tr>
<td style="padding-top:30" width="142" align="left" valign="top" bgcolor="#D6E4F5" class="navBG">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="middle"><a href="home.html" class="mainInactiveBlue">home
</a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="aboutUs.html" class="mainInactive">about
us</a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="ourAdvisers.html" class="mainInactiveBlue">our
advisers </a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="services.html" class="mainInactive">services</a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="testimonials.html" class="mainInactiveBlue">testimonials</a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="financialTest.asp" class="navActive">financial
test </a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="learningCentre.html" class="mainInactiveBlue">learning
centre </a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="clientLogin.html" class="mainInactive">client
login </a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href=" class="mainInactiveBlue">advisory
zone </a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="community.html" class="mainInactive">community</a></td>
</tr>
<tr>
<td align="right" valign="middle"><a href="contact.html" class="mainInactiveBlue">contact
us </a></td>
</tr>
<tr>
<td align="right" valign="middle">&nbsp;</td>
</tr>
</table>
<img src="images/spacer.gif" width="142" height="20"></td>
<td width="623" align="left" valign="top" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top" style="padding-left:30;padding-right:26;padding-top:30">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"><span class="black18">How Financially
Organised Are You</span><br> <br>
<span class="black11">To help raise your awareness and so you
can clearly understand your current situation, please take the
time to complete the following &#8216;scorecard&#8217;. Rate
your reaction to each pair of phrases. Decide where you lie
on the scale from 1 to 10. When complete hit the &quot;Get Results&quot;button
which will show you your score and give you to chance to email
the completed scorecard to us so that your adviser can help
you understand the significance of your score.</span><br>
<br>
<form action="" method="post" name="formTestResults" class="formBorder" id="formTestResults">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#666666"><table width="250" border="0" cellspacing="1" cellpadding="0">
<tr bgcolor="#CCCCCC">
<td align="center" valign="top" class="formText"><strong>Question</strong></td>
<td colspan="2" align="center" valign="middle" class="black11"><strong>Results</strong></td>
</tr>
<tr bgcolor="#F2F2F2">
<td width="96" align="center" valign="top" class="formText">1.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("one") %></strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center" valign="top" class="formText">2.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("two") %></strong></td>
</tr>
<tr bgcolor="#F2F2F2">
<td align="center" valign="top" class="formText">3.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("three") %></strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center" valign="top" class="formText">4.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("four") %></strong></td>
</tr>
<tr bgcolor="#F2F2F2">
<td align="center" valign="top" class="formText">5.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("five") %></strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center" valign="top" class="formText">6.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("six") %></strong></td>
</tr>
<tr bgcolor="#F2F2F2">
<td align="center" valign="top" class="formText">7.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("seven") %></strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center" valign="top" class="formText">8.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("eight") %></strong></td>
</tr>
<tr bgcolor="#F2F2F2">
<td align="center" valign="top" bgcolor="#F2F2F2" class="formText">9.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("nine") %></strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center" valign="top" class="formText">10.</td>
<td colspan="2" align="center" valign="bottom" class="formText"><strong><%= Request.Form("ten") %></strong></td>
</tr>
<tr bgcolor="#F2F2F2">
<td colspan="3" align="left" valign="top" class="formText">&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" align="center" valign="middle" class="formText">Your
score: </td>
<td width="204" align="center" valign="top" class="formText"><strong><%
myscore=0
for each element in request.form
if left(element,5) = "radio" then
MyScore = MyScore + Cint(request(element))
End If
next
%>
<script language="javascript">
alert("your score was <%=myscore%>");
</script></strong>

</td>
</tr>
</table></td>
</tr>
</table>
<br>
<span class="black11">Ullamco laboris nisi lorem ipsum dolor
sit amet, consectetur adipisicing elit. Excepteur sint occaecat
in reprehenderit in voluptate quis nostrud exercitation. Sed
do eiusmod tempor incididunt mollit anim id est laborum. Duis
aute irure dolor qui officia deserunt eu fugiat nulla pariatur</span>.<br>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="29%" class="formText">Name:</td>
<td width="71%"><input name="textfield" type="text" class="textField" size="25"></td>
</tr>
<tr>
<td class="formText">Phone (Work):</td>
<td><input name="textfield2" type="text" class="textField" size="25"></td>
</tr>
<tr>
<td class="formText">Phone (Home):</td>
<td><input name="textfield3" type="text" class="textField" size="25"></td>
</tr>
<tr>
<td class="formText">Phone (Mobile):</td>
<td><input name="textfield4" type="text" class="textField" size="25"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" class="formButton" value="Submit"></td>
</tr>
</table>
<br>

</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><hr size="1"></td>
</tr>
<tr>
<td align="right" valign="top" class="blue11"><a href="#top">Back
to Top</a></td>
</tr>
</table> </td>
</tr>
</table>
</td>
</tr>
</table>
<img src="images/spacer.gif" width="623" height="50"></td>
</tr>
<tr align="center" valign="middle" bgcolor="#1E569F">
<td height="70" colspan="2" class="footerBG"><span class="white9"><a href="home.html">Home</a>
&#124; <a href="aboutUs.html">About Us</a> &#124; <a href="ourAdvisers.html">Our
Advisers</a> &#124; <a href="services.html">Services</a> &#124; <a href="testimonials.html">Testimonials</a>
&#124; <a href="financialTest.asp">Financial Test</a> &#124; <a href="learningCentre.html">Learning
Centre</a> &#124;<br>
<a href="clientLogin.html">Client Login</a> &#124; <a href=" Zone</a> &#124; <a href="community.html">Community</a> &#124; <a href="contact.html">Contact
Us</a><br>
<br>
<strong>Fitzpatricks</strong> Suite C Level 2 Showcase Building Marine Parade
Coolangatta QLD 4225&nbsp;&nbsp;|&nbsp;&nbsp;<strong>Phone:</strong> 07
5599 1999&nbsp;&nbsp;|&nbsp;&nbsp;<a href="mailto:invest@fitz.com.au">invest@fitz.com.au</a></span></td>
</tr>
</table>
</body>
</html>


Thanks
 
ok replace this block of code :
Code:
<%
myscore=0
for each element in request.form
  if left(element,5) = "radio" then 
    MyScore = MyScore + Cint(request(element))
  End If
next
%>
<script language="javascript">
  alert("your score was <%=myscore%>");
</script>

with

Code:
<%
myscore=0
ScoreItems = Split("one,two,three,four,five,six,seven,eight,nine,ten",",")
for each item in ScoreItems
  MyScore = MyScore + Cint(request(item))
next
Response.Write myscore
%>

[thumbsup2]DreX
aKa - Robert
 
Check it out mate.

Works beautifully.

Cant thank you enough!

Appreciate the help and will return to this forum many many times. You have saved me money.

Reagrds
Enzo Banzai
aka. David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top