tcertain
10-17-2008, 02:19 PM
I am trying to figure out javascript with 2 books I purchased with no luck. I have searched for weeks for a script on the internet that would work for me with no luck. I am posting what I have in my form and the javascript I have (it doesn't work) and maybe someone can tell me how to get this working before I pull all my hair out! If someone can recommend a JS book that will start from the beginning for javascript challenged minds I would appreciate that also.
What I need is to take the radio box value and the checkbox values that are clicked and add them up at the bottom in a total box. I don't care whether the box total is by a button that adds them up at the click of the button, or it is a running total in the box.
HTML page
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Estimator</title>
</head>
<html>
<body>
<form method="post" action="" name="cost_estimator">
<fieldset name="General">
<legend class="alignleft">General</legend>
<p>
<input name="General" type="radio" checked="checked" value="0"onchange="Totals(this.form)"/>
I have an existing website. (0 hours)</p>
<p><input name="General" type="radio" value="3" onchange="(Totals)"/>
I need a basic blog site. (3 hours)</p>
<p>
<input name="General" type="radio" value="6" /> I
need a basic, off the shelf, template based site set-up.
(6 hours)</p>
<p><input name="General" type="radio" value="1" /> I
need a completely custom site. (15 hours)<br />
</p>
</fieldset>
<fieldset name="SEO">
<legend class="alignleft">SEO</legend>
<p><input name="MetaTag" type="checkbox" />
MetaTag Keyword Optimization (5 hours)</p>
<p><input name="Search_Engine_Submission" type="checkbox" />
Search Engine Submission (3 hours)</p>
<p><input name="Link_Building" type="checkbox" />
Minor Link Building (6 hours)</p>
</fieldset>
<div>
<div>
<input name="Totals" type="text" <script type="text/javascript" src="Totals.js"></script>Total Hours for your site<br />
</div>
</form>
</body>
</html>
the external script
function Totals(f)
{
var nums = f.num;
var result = 0;
for(var i=0;i++)
{
if(nums[i].checked)
{
result+=parseFloat(ntext[i].value);
}
}
f.answer.value=result;
}
What I need is to take the radio box value and the checkbox values that are clicked and add them up at the bottom in a total box. I don't care whether the box total is by a button that adds them up at the click of the button, or it is a running total in the box.
HTML page
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Estimator</title>
</head>
<html>
<body>
<form method="post" action="" name="cost_estimator">
<fieldset name="General">
<legend class="alignleft">General</legend>
<p>
<input name="General" type="radio" checked="checked" value="0"onchange="Totals(this.form)"/>
I have an existing website. (0 hours)</p>
<p><input name="General" type="radio" value="3" onchange="(Totals)"/>
I need a basic blog site. (3 hours)</p>
<p>
<input name="General" type="radio" value="6" /> I
need a basic, off the shelf, template based site set-up.
(6 hours)</p>
<p><input name="General" type="radio" value="1" /> I
need a completely custom site. (15 hours)<br />
</p>
</fieldset>
<fieldset name="SEO">
<legend class="alignleft">SEO</legend>
<p><input name="MetaTag" type="checkbox" />
MetaTag Keyword Optimization (5 hours)</p>
<p><input name="Search_Engine_Submission" type="checkbox" />
Search Engine Submission (3 hours)</p>
<p><input name="Link_Building" type="checkbox" />
Minor Link Building (6 hours)</p>
</fieldset>
<div>
<div>
<input name="Totals" type="text" <script type="text/javascript" src="Totals.js"></script>Total Hours for your site<br />
</div>
</form>
</body>
</html>
the external script
function Totals(f)
{
var nums = f.num;
var result = 0;
for(var i=0;i++)
{
if(nums[i].checked)
{
result+=parseFloat(ntext[i].value);
}
}
f.answer.value=result;
}