javascript - Converter boxes, How to make it both output boxes work? -


i doing project of converter. when put number in number box, shows fine in box2. when try enter number in box2, , won't show answer in box1. can me? don't know jquery , starter of html , javascript. hopefully, can me. thanks

function numbertosquare(num)  {   var sqrt;   sqrt = math.sqrt(num);   return sqrt;   }     function squaretonumber(sqrt)  {   var num;   num = math.pow(sqrt,2);   return num;   } 
<html>  <head>  <title>program assignment 5</title>    <script type = text/javascript src = "calculate.js"> </script>     <script type="text/javascript">  function converttosqrt()    //assumes: number contains number    //results: displays square root in box2    {      num = parsefloat(document.getelementbyid('box1').value);      sqrt = numbertosquare(num);      box2.value=sqrt;    }        function converttonum()    //assumes: square contains number of square root    //results: displays number in box1    {      sqrt = parsefloat(document.getelementbyid('box2').value);      num = squaretonumber(sqrt);      box1.value=num;    }  </script>    </head>      <body>  <div style="border: solid; width: 300px; background-color: #83caff">    <table>  <th></th> <th>square root calculation</th>  <tr>  <th>enter number:</th><th><input type="number" id="box1" value=""></th>  <tr>  <th>squareroot:</th><th><input type="number" id="box2" value=""></th>  <tr>  <th></th><th><input type="button" value="calculate" onclick="converttosqrt(); converttonum();">  </table>  </div>

if helps any, here's quick sample. it's not pretty can take pieces need , use own.

<html>  <head>      <title></title>      <script>          function calc(which) {              var newval;              if (which == "sqrt") {                  newval = parsefloat(document.getelementbyid("num").value);                  newval = math.sqrt(newval);              }              else if (which == "num") {                  newval = parsefloat(document.getelementbyid("sqrt").value);                  newval = math.pow(newval, 2);              }                document.getelementbyid(which).value = newval;          }      </script>  </head>  <body>      <div style="width:400px;padding:25px;display:inline-block;line-height:150%;background-color:#83caff;font-weight:bold;border:solid 1px black;">          <div style="width:200px;float:left;">              <label>number:</label>              <br />              <label>squareroot:</label>          </div>          <div style="width:200px;float:right;">              <input type="number" id="num"/>              <br />              <input type="number" id="sqrt"/>          </div>          <button type="button" style="width:100%;" onclick="calc('sqrt');">calc sqrt</button>          <button type="button" style="width:100%;" onclick="calc('num');">calc num</button>      </div>  </body>  </html>


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -