pml
03-13-2005, 04:43 PM
I wonder why I can't use the "document.write (Total)" in the end. The sum should also change evertime
a form element is clicked and be displayed on the page as text(not by using an alert box like function "Calculate2").
In which ways would the answer change if I had prefered the sum to be displayed in another frame, named "frame2"?
The form below is in "frame1".
Unfortunately I can't get the checkboxes to behave like the radio buttons either.
Can anyone help me with these problems?
<html>
<head>
<script language="javascript" type="text/javascript">
var MyArray = new Array(0,0,0,0);
function Calculate (nr, value) {
MyArray[nr] = value;
Calculate2();
}
function Calculate2() {
var Total = parseInt(document.MyForm.SecretField.value);
var JoinedArray = MyArray.join("+");
Total = Total + eval(JoinedArray);
//alert ("Total value is" + Total);
}
</script>
</head>
<body onLoad="Calculate2()">
<p>
<form name="MyForm">
<p>The default value is 10.</p>
<p>
<input name="RadioGroup1" type="radio" value="SomeValue1" checked onClick="Calculate(0, 0)">
<br>
<input name="RadioGroup1" type="radio" value="SomeValue2" onClick="Calculate(0, 2)">
Add 2 <br>
<input name="RadioGroup1" type="radio" value="SomeValue3" onClick="Calculate(0, 3)">
Add 3 <br>
<input name="check1" type="checkbox" id="check1" value="SomeValue4" onClick="Calculate(1, 8)">
Add 8</p> </p>
<p>
<input name="RadioGroup2" type="radio" value="SomeValue5" checked onClick="Calculate(2, 0)"> <br>
<input name="RadioGroup2" type="radio" value="SomeValue6" onClick="Calculate(2, 3)">
Add 3 <br>
<input name="RadioGroup2" type="radio" value="SomeValue7" onClick="Calculate(2, 9)">
Add 9 <br>
<input name="check2" type="checkbox" value="SomeValue8" onClick="Calculate(3, 12)">
Add 12 </p>
<input type="hidden" name="SecretField" value="10">
</form>
The total value is:
<script language="javascript" type="text/javascript">
doucment.write (Total);
</script>
</body>
</html>
a form element is clicked and be displayed on the page as text(not by using an alert box like function "Calculate2").
In which ways would the answer change if I had prefered the sum to be displayed in another frame, named "frame2"?
The form below is in "frame1".
Unfortunately I can't get the checkboxes to behave like the radio buttons either.
Can anyone help me with these problems?
<html>
<head>
<script language="javascript" type="text/javascript">
var MyArray = new Array(0,0,0,0);
function Calculate (nr, value) {
MyArray[nr] = value;
Calculate2();
}
function Calculate2() {
var Total = parseInt(document.MyForm.SecretField.value);
var JoinedArray = MyArray.join("+");
Total = Total + eval(JoinedArray);
//alert ("Total value is" + Total);
}
</script>
</head>
<body onLoad="Calculate2()">
<p>
<form name="MyForm">
<p>The default value is 10.</p>
<p>
<input name="RadioGroup1" type="radio" value="SomeValue1" checked onClick="Calculate(0, 0)">
<br>
<input name="RadioGroup1" type="radio" value="SomeValue2" onClick="Calculate(0, 2)">
Add 2 <br>
<input name="RadioGroup1" type="radio" value="SomeValue3" onClick="Calculate(0, 3)">
Add 3 <br>
<input name="check1" type="checkbox" id="check1" value="SomeValue4" onClick="Calculate(1, 8)">
Add 8</p> </p>
<p>
<input name="RadioGroup2" type="radio" value="SomeValue5" checked onClick="Calculate(2, 0)"> <br>
<input name="RadioGroup2" type="radio" value="SomeValue6" onClick="Calculate(2, 3)">
Add 3 <br>
<input name="RadioGroup2" type="radio" value="SomeValue7" onClick="Calculate(2, 9)">
Add 9 <br>
<input name="check2" type="checkbox" value="SomeValue8" onClick="Calculate(3, 12)">
Add 12 </p>
<input type="hidden" name="SecretField" value="10">
</form>
The total value is:
<script language="javascript" type="text/javascript">
doucment.write (Total);
</script>
</body>
</html>