I'm stuck guys please help!

admin

Administrator
Staff member
Hi,

I am new to programming, hope this makes sense. I am writing a JavaScript on that will basically add numbers an user inputs in a form field. right now there are 8 fields. The script seems to work find until I decided I want to add a validation to the script. All I want is the validation to do is if the total goes over 75 and if the "total" input field is selected first a pop up alert will appear. Can't get it right ugh! frustrated and tired with no one to turn but this forum...below is my messy code...hope someone out there can fix this :(

Thanks.;)



<SCRIPT LANGUAGE="JavaScript">



<!-- Begin
function a_plus_h(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=eval(form.c.value)
d=eval(form.d.value)
e=eval(form.e.value)
f=eval(form.f.value)
g=eval(form.g.value)
h=eval(form.h.value)
i=a+b+c+d+e+f+g+h
form.ans.value = i

var cert=document.formx.ans
if ((cert.value=="0")||(cert.value==null)){
alert("you have to fill in other fields first")
cert.focus()
return false
}
else if (cert.value < 75){
alert("hi you can only have max of 75")
cert.focus()
return false
}
return true
}

// End -->

</script>


<CENTER>

<FORM name="formx">
<input type="number" size=4 value=http://www.webdeveloper.com/forum/archive/index.php/"" name="a">
<input type="number" size=4 value="" name="b">
<input type="number" size=4 value="" name="c">
<input type="number" size=4 value="" name="d">
<input type="number" size=4 value="" name="e">
<input type="number" size=4 value="" name="f">
<input type="number" size=4 value="" name="g">
<input type="number" size=4 value="" name="h"> <br>
total
<input type "number" value="" name="ans" size=9 onFocus=a_plus_h(form)>
</FORM>
</CENTER>
 
Back
Top