PDA

View Full Version : Why this is not working?



Darkmirror
11-01-2009, 02:39 PM
Script::.


<script language="javascript">
function temp(form)
{
oops = "";
var sum = 0;
var fld = (form.level.value);
var val = fld.value.replace(/\s/g, "" );
if ( val != "")
{
var deg = parseFloat(fld.value);
if ( isNaN(deg) || deg < 0)
{
fld.value = "0";
oops += "\nInvalid Level";
} else if ( deg != 0 ) {
sum += Math.pow( deg, 3 );}
}
if ( oops != "" )
{
alert("You must correct these errors:\n" + oops);
return false;
}
form.totalexp.value = sum ;
}
</script>

Html::.


<form style="text-align:center">
<p>Level</p>
<p><input size=30 maxlength=30 value=0 name="level" onfocus="this.value=''"/></p>
<input type=button onclick=temp(this.form) value=Calculate />
<input type=reset name=clear id=clear value=Clear /></p>
<blockquote><p>Total Exp <input name="totalexp" size=40 maxlength=40 readonly=""/></p></blockquote></form>

Can someone help me. Whats wrong with my js code and i am noob to J.S.
Your help is most appreciated.

jscheuer1
11-01-2009, 04:24 PM
Get rid of the highlighted:


function temp(form)
{
oops = "";
var sum = 0;
var fld = (form.level.value);
var val = fld.val . . .

Darkmirror
11-01-2009, 07:50 PM
Thank you very much for ur time!