HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 20th, 2004, 04:04 PM
ErockMahan ErockMahan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 ErockMahan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation HTML Adding numbers from radio buttons

For starters, I am trying to avoid adding <script language="JavaScript"> and other such functions to my webpages, as there are many things that I do not, and will not understand about it. Nevertheless, if my problem cannot be solved without doing so, please just let it be JavaScript and not Perl or something else. Thank you

Now, the dumbed-down version of what I am trying to do is create a webpage (meaning .html) with many different radio buttons. That's the easy part.

Each of the radio buttons will have a numeric value attatched to them. Like so:

<input type="radio" name="one" value=0 checked>Zero
<input type="radio" name="one" value=1>One
<input type="radio" name="one" value=2>Two
<BR>
<BR>
<input type="radio" name="two" value=0 checked>Zero
<input type="radio" name="two" value=1>One
<input type="radio" name="two" value=2>Two

But many more instances of zero through two. Approximately 50 times.

What I want to have happen, ultimately, is the hard part that I can't seem to figure out.

At the bottom of the page I want to have a box (still easy) that will display (still easy) the total number of times the option "one" was selected (hard!), then next to it another box (easy again) showing the number of times the option "two" was selected (hard again), and so on.

If someone can help me learn how to do this, the rest of what I need to do should be rather simple.

And for those of you wondering what in the world I would want this for, it is for a study of human behavior. Some people aren't as random as they want to be, you know? Anyway, thanks a lot for your help if you can give it!

Reply With Quote
  #2  
Old September 20th, 2004, 05:25 PM
selwonk's Avatar
selwonk selwonk is offline
Contributing User
ASP Free Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2004
Posts: 2,942 selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level)selwonk User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 9 h 49 m 28 sec
Reputation Power: 62
Hi

The following is a straight forward ASP script that uses arrays to build the question set. The only thing I've not done is to make the zero default when the script is run for the first time (I forgot that bit):
Code:
<%
Dim ary_AlphaNumbers(9)
ary_AlphaNumbers(0) = "one"
ary_AlphaNumbers(1) = "two"
ary_AlphaNumbers(2) = "three"
ary_AlphaNumbers(3) = "four"
ary_AlphaNumbers(4) = "five"
ary_AlphaNumbers(5) = "six"
ary_AlphaNumbers(6) = "seven"
ary_AlphaNumbers(7) = "eight"
ary_AlphaNumbers(8) = "nine"
ary_AlphaNumbers(9) = "ten"
%>
<%
Dim ary_NumbersToWords(2)
ary_NumbersToWords(0) = "Zero"
ary_NumbersToWords(1) = "One"
ary_NumbersToWords(2) = "Two"
%>
<html>
<head>
<title>Check box demo</title>
</head>
<body>
<form method="post">
<%
For int_Counter = 0 TO UBound(ary_AlphaNumbers)
For int_InnerCounter = 0 TO 2
If Request.Form(ary_AlphaNumbers(int_Counter)) = CStr(int_InnerCounter) Then str_Checked = " checked" Else str_Checked = "" End If
Response.Write("<input type=""radio"" name=""" & ary_AlphaNumbers(int_Counter) & """ value=""" & int_InnerCounter & """" & str_Checked & ">&nbsp;" & ary_NumbersToWords(int_InnerCounter) & "<br>" & vbcrlf)
Next
Response.Write("<p>" & vbcrlf)
Next
%>
<input type="submit">
</form>
<hr>
<%
int_Zeros = 0
int_Ones = 0
int_Twos = 0
For Each str_ItemFound In Request.Form
Select Case Request.Form(str_ItemFound)
Case 0
	int_Zeros = int_Zeros + 1
Case 1
	int_Ones = int_Ones + 1
Case 2
	int_Twos = int_Twos + 1
End Select
Next
%>
Number of zeros selected = <b><%= int_Zeros %></b><br>
Numbers of ones selected = <b><%= int_Ones %></b><br>
Number of twos selected = <b><%= int_Twos %></b>
</body>
</html>
__________________
selwonk

If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more!

Reply With Quote
  #3  
Old September 21st, 2004, 01:46 PM
ErockMahan ErockMahan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 ErockMahan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Uh, I am pretty sure that is beyond me and my understanding. I'll give it a try, but if there are any other solutions to my little query, I'd be more than glad to hear them.

Reply With Quote
  #4  
Old September 22nd, 2004, 07:18 AM
mzijlstra mzijlstra is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 11 mzijlstra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

ErockMahan,

I have made the next file and checked it. In my opinion it works. Is this what you want?


Code:
<html>
<head>
<script type="text/javascript">
<!--
function checkSelections (obj)
{ 
 var frm = document.forms("form1");
 var numChecked = 0;
 var numberOfElements = 6; // in your case 50;
 for (i=1; i<=numberOfElements; i++)
 { 
  if (frm.elements(obj + "." + i).checked == true) 
  {
	numChecked++;
  }
 }
 frm.elements("txt" + obj).value = numChecked;
}

//-->
</script>
</head>
<body>
<form name="form1">
<table>
<tr>
<td>
<input type=checkbox name="1.1" value="1" onclick="checkSelections('1');">1
<input type=checkbox name="1.2" value="2" onclick="checkSelections('1');">2
<input type=checkbox name="1.3" value="3" onclick="checkSelections('1');">3
<input type=checkbox name="1.4" value="4" onclick="checkSelections('1');">4
<input type=checkbox name="1.5" value="5" onclick="checkSelections('1');">5
<input type=checkbox name="1.6" value="6" onclick="checkSelections('1');">6
<BR>
number of selected items:
<input type=text name="txt1" size=10>
</td>
<td>
<input type=checkbox name="2.1" value="1" onclick="checkSelections('2');">1
<input type=checkbox name="2.2" value="2" onclick="checkSelections('2');">2
<input type=checkbox name="2.3" value="3" onclick="checkSelections('2');">3
<input type=checkbox name="2.4" value="4" onclick="checkSelections('2');">4
<input type=checkbox name="2.5" value="5" onclick="checkSelections('2');">5
<input type=checkbox name="2.6" value="6" onclick="checkSelections('2');">6
<BR>
number of selected items:
<input type=text name="txt2" size=10>
</td>
</tr>
</table>
</form>
</body>
</html>


Greetz,

Mario

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > HTML Adding numbers from radio buttons


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway