if statment inside a function JavaScript

Soldato
Joined
2 Oct 2003
Posts
2,846
Location
MI5 | Thames House
can you have if statments inside functions like I have below its just the code below works but it doesnt output the comment part at all . any idea sorry

Code:
<SCRIPT language=JavaScript>


function perc1() {
 a = document.form1.a.value;
 b = a*document.form1.b.value;
 document.form1.total1.value = b;
 
[B] if (total1 <10) {
          form1.comment1.value="some random commet 1 ";
       }

       else if (total1 >40) {
          form1.comment1.value="some random comment 2 ";
}

       }[/B]
    
 

</SCRIPT>
 
'totall' isn't a variable, you need to set it up as a variable and assign it a value. So if you're wanting 'totall' variable to have the same value as the form element -
Code:
var totall = b;
 
Back
Top Bottom