Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: quadratic

  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    quadratic

    Code:
    <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?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,045
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <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>

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thx. i will test that out


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •