Click to See Complete Forum and Search --> : simply adding form selection values
catchup
04-26-2003, 06:14 PM
it keeps returning 15, i would like it to add the option values... please help. also to include an alert if nothing is selected, i tried doing this think that if nothing is selected then ada must = 0 so alert user to select. thanks ;)
<html><head>
<script language="JavaScript"><!--
function AddRadioButtons () {
var itemchecked = false;
var ada = 0;
var ada = parseFloat(document.form.ada1.value)+parseFloat (document.form.a2.value)+parseFloat (document.form.a3.value)+parseFloat (document.form.a4.value)+parseFloat (document.form.a5.value)+parseFloat (document.form.a6.value)+parseFloat (document.form.a7.value);
if(ada>15) {
ada = 15;
} else {
if ada= 0 {
alert("Please select an Education Level");
}
}
document.write (ada)
}
//--></script>
</head><body><form name="form">
<input type="radio" value="5" name="a1">
<input type="radio" value="7" name="a2">
<input type="radio" value="9" name="a3">
<input type="radio" value="12" name="a4">
<input type="radio" value="12" name="a5">
<input type="radio" value="12" name="a6">
<input type="radio" value="12" name="a7">
<input type="Submit" value="Next" onclick="AddRadioButtons();"/>
</form></body></html>
AdamBrill
04-26-2003, 07:40 PM
Here, try this:<html><head>
<script language="JavaScript"><!--
function AddRadioButtons () {
var itemchecked = false;
var ada = 0;
frm = document.form1;
x=1;
while(eval("frm.a"+x)){
if(eval("frm.a"+x+".checked")){
ada+=parseInt(eval("frm.a"+x+".value"));
}
x++;
}
if(ada>15) {
ada = 15;
} else {
if (ada == 0) {
alert("Please select an Education Level");
return false;
}
}
document.write (ada)
}
//--></script>
</head><body><form name="form1">
<input type="radio" value="5" name="a1">
<input type="radio" value="7" name="a2">
<input type="radio" value="9" name="a3">
<input type="radio" value="12" name="a4">
<input type="radio" value="12" name="a5">
<input type="radio" value="12" name="a6">
<input type="radio" value="12" name="a7">
<input type="Submit" value="Next" onclick="AddRadioButtons();"/>
</form></body></html>BTW, you might want to change them from radio buttons to checkboxes. Right now, after they select it, they can't unselect it... ;)
catchup
04-26-2003, 10:46 PM
Wow thanks, i learned a lot from that :)
I'm trying to post the ada value to another page but the value passes always as zero, i removed the alert as that was for testing. Does the ada value need to be in a different format to send to another page via the url?
AdamBrill
04-26-2003, 11:03 PM
No, you can send it like that. Just do it like this:
document.location = "wherever.htm?"+ada;
That should put the value of ada after the ?. I hope that helps! ;)
catchup
04-27-2003, 11:07 AM
sending it worked, the form was set to send on the desktop but functionality was not set for the internet :rolleyes: thanks!
I was fooling around with your scripts and thought i'd try something a little different and was wondering why it wouldn't work, Suspose instead of adding up all the values, lets say i had 2 sets to add up and each set had 3 of its own sets, to simplify things, let say i was doing a language assessment
that user may also note the level of language abilities in both languages; however, only the highest scoring language ability score will be considered. so it would be set up in a table to something like this:
English---read---write---speak
excellent-e1-----e2------e3
well-------e1-----e2------e3
poor------e1-----e2------e3
French-----read-----write-----speak
excellent----f1-------f2--------f3
well----------f1-------f2--------f3
poor---------f1-------f2--------f3
(e1,e2...f1,f2... are radio names) So i'm basically trying to add up the English values and then the French and if (english summed selected values) > or = (french summed selected values) then var lan = english
or
if french > english then lan = french
I tried to extend the orginal script to include the new options but it donesn't want to work, can i not extend the current script like so, but teh script only produces lan = 0
function Process () {
var itemchecked = false;
var data = "";
var a1 = a2 = lan = 0;
fr1 = document.f8;
x=1;
while(eval("fr1.e"+x)){
if(eval("fr1.e"+x+".checked")){
a1+=parseInt(eval("fr1.e"+x+".value"));
}
x++;
}
fr2 = document.f8;
y=1;
while(eval("fr2.f"+x)){
if(eval("fr2.f"+y+".checked")){
a2+=parseInt(eval("fr2.f"+y+".value"));
}
y++;
}
if (a1 > a2) {
lan = a1;
}else{
if (a2 > a1) {
lan = a2;
}else{
if (a2 = a1) {
lan = a1;
}
}
}
}