|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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 & "> " & 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! |
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > HTML Adding numbers from radio buttons |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|