Hi Jasper,
(lawlz sorry the real answer’s at the bottom if you’re in a hurry!)
lemme start out by saying, ignore the goofy badge under my name. I’m a JS newb. But I can take some not-so-wild guesses and I can give you something that’s good advice.
First, language=javascript is deprecated… that doesn’t mean it doesn’t work, it just means everyone decided to stop doing it back when grunge bands were all the rage. Your scripts tags should be <script type=“text/javascript”>
(no it doesn’t affect your script running)
Second, since I’m going on about somewhat unimportant things, your form needs a block child to be valid. The inputs are inline and forms can’t have those as direct children. Wrapping a div around the inputs (or ideally a fieldset) would make the form valid: <form><div><input/><input/><input/><input/></div></form>
(no it also doesn’t affect your script running)
Third, you’re calling your function at each input. The whole function. Not just the assignments you want. And twice on the third input. That can’t be right… the whole function is probably puking every time (I’m not sure) because it can’t finish until it’s got all those variables…
instead you should be able to call the thing just once, I’d say with the onblur on the last input. The variables will get assigned at that point.
num4=num1-num2-num3;
When real humans start filling this stuff in you may want some checking in there to make sure num1 really is bigger than num2 or num3. Right now you’re assuming people will be smart. Never assume that. If the above equation gives you -44.35, that’s a number, so the check for NaN won’t catch anything there.
if(isNaN(num4))
{
num4=“maybe put some test text here for now… or let people know their inputs were somehow invalid”;
}
…and
document.getElementById(“total”).equity = num4;
The current value of the input, before the function runs, is “equity”.
you meant:
document.getElememtById(“total”).value = num4;
so, when we said “value” we didn’t mean your current value. We meant the property called “value” of the form control.