...

View Full Version : quadratic



VietBoyVS
02-06-2004, 08:33 AM
<form name="quadratic" id="quadratic">
<table width="200" border="0" cellspacing="2" cellpadding="1">
<tr>
<td><div align="center">A (X<sup>2</sup>)</div></td>
<td><div align="center">B(X)</div></td>
<td><div align="center">C</div></td>
</tr>
<tr>
<td><input name="a" type="text"></td>
<td><input name="b" type="text"></td>
<td><input name="c" type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><center><input name="calculate" type="button" value=" Calculate " onClick="quad()"></center></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">ROOT 1: </div></td>
<td><input name="root1" type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">ROOT 2: </div></td>
<td><input name="root2" type="text"></td>
</tr>
</table>
</form>

<script language = "JavaScript">
function quad() {
ROOTA = (( -b.value) + sqrt(b.value * b.value - 4 * a.value * c.value)) / ( 2 * a.value );
document.quadratic.root1.value = Math.round(ROOTA)/1000;
ROOTB = (( -b.value) - sqrt(b.value * b.value - 4 * a.value * c.value)) / ( 2 * a.value );
document.quadratic.root2.value = Math.round(ROOTB)/1000;
}
</script>


Why doesn't this work?

glenngv
02-06-2004, 08:54 AM
<html>
<head>
<script language = "JavaScript">
function quad(f) {
var a = f.a.value;
var b = f.b.value;
var c = f.c.value;
var ROOTA = (-a + Math.sqrt(b * b - 4 * a * c)) / ( 2 * a );
f.root1.value = Math.round(ROOTA)/1000;
var ROOTB = (-b - Math.sqrt(b * b - 4 * a * c)) / ( 2 * a );
f.root2.value = Math.round(ROOTB)/1000;
}
</script>
</head>
<body>
<form name="quadratic" id="quadratic">
<table width="200" border="0" cellspacing="2" cellpadding="1">
<tr>
<td><div align="center">A (X<sup>2</sup> )</div></td>
<td><div align="center">B(X)</div></td>
<td><div align="center">C</div></td>
</tr>
<tr>
<td><input name="a" type="text"></td>
<td><input name="b" type="text"></td>
<td><input name="c" type="text"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><center><input name="calculate" type="button" value=" Calculate " onClick="quad(this.form)"></center></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><div align="center">ROOT 1: </div></td>
<td><input name="root1" type="text"></td>
</tr>
<tr>
<td> </td>
<td><div align="center">ROOT 2: </div></td>
<td><input name="root2" type="text"></td>
</tr>
</table>
</form>
</body>
</html>

VietBoyVS
02-06-2004, 09:17 AM
thx. i will test that out



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum