I have this JavaScript:
function Pythag1(){
var inputa = document.getElementById("input1");
var a = inputa.value;
var inputb = document.getElementById("input2");
var b = inputb.value;
if (b == "" || c == "" || isNaN(c) || isNaN(b)){
alert("Try again!");
}
else{
alert("C=" + Math.sqrt((a*a) + (b*b)));
}
}
/*above does not work*/
function Pythag2(){
var inputbc = document.getElementById("input3");
var sb = inputb.value;
var inputc = document.getElementById("input4");
var c = inputc.value;
if (sb == "" || c == "" || isNaN(c) || isNaN(sb) || (sb > c)){
alert("Try again!");
}
else{
alert("A=" + Math.sqrt((c*c) - (sb*sb)));
}
}
and HTML:
<h3 style="text-align:left;">Pythagorean Theorem 1</h3>
<form>
A=<input type="text" id="input1" value="" name="aval" /><br />
B=<input type="text" id="input2" value="" name="bval" /><br />
<input type="submit" onclick="Pythag1()" />
</form>
<h3 style="text-align:left;">Pythagorean Theorem 2</h3>
<form>
B=<input type="text" id="input3" value="" name="bval2" /><br />
C=<input type="text" id="input4" value="" name="cval" /><br />
<input type="submit" onclick="Pythag2()" />
</form>
The Pythag2() function works, but the Pythag1() doesn’t. Any ideas?
The
cvariable you are using in theifcondition doesn’t seem to be defined anywhere. Maybe you meant: