html - Express/Solve formula with Javascript -


i trying create form allow variables inputted , given formula solved. stumbling on how express formula , how make first 2 variables understood exponent.

here complete formula works in excel (cell labels replaced input names html):

=varnk * varqr * ( 273 + vart ) / ( 273 + varto ) * varpp / varp * varkq * varkak 

note "varnk" , "varqr" values entered exponents - i.e. 97.53^12

edit: actual formula (link image don't have enough rep post directly)- http://mattk.net/dwformula1.png

here attempted make work. wasn't sure correct way assemble final output, ideally want figure out how make single button operation.

<head>    <script>       function docalcone()       {       var varnk = document.getelementbyid('varnk').value;           var varqr = document.getelementbyid('varqr').value;          var vart = document.getelementbyid('vart').value;       var varto = document.getelementbyid('varto').value;       var varpo = document.getelementbyid('varpo').value;       var varp = document.getelementbyid('varp').value;       var varkq = document.getelementbyid('varkq').value;       var varkak = document.getelementbyid('varkak').value;        var result1 = document.getelementbyid('stepone');       var stepone = varnk * varqr;       result1.value = stepone;        }       function docalctwo()       {       var result2 = document.getelementbyid('steptwo');       var steptwo = parseint(vart.value) + 273;       result2.value = steptwo;       }    </script> </head> <html>    <table>       <tr>          <td>step one:<input id="stepone" /></td>       </tr>       <tr>          <td>step two:<input id="steptwo" /></td>       </tr>    </table>    <div id="doseratecalc">       <p>enter values below calculate dose rate</p>    </div>    <table style="width:600px;border:1px solid #000;">       <tr>          <td>             <p>nk=<input id="varnk" type="text"></p>          </td>          <td>             <p>tn 34013 ic cal certificate detection calibration factor</p>          </td>       <tr>          <td>             <p>qr=<input id="varqr" type="text"></p>          </td>          <td>             <p>unidos measured charge in pc (pico coulumb)@20mm</p>          </td>       </tr>       <tr>          <td>             <p>t=<input id="vart" type="text"></p>          </td>          <td>             <p>current temperature</p>          </td>       </tr>       <tr>          <td>             <p>to=<input id="varto" type="text"></p>          </td>          <td>             <p>tn34013 ic cal certificate protocol temp</p>          </td>       </tr>       <tr>          <td>             <p>po=<input id="varpo" type="text"></p>          </td>          <td>             <p>current pressure</p>          </td>       </tr>       <tr>          <td>             <p>p=<input id="varp" type="text"></p>          </td>          <td>             <p>tn34013 ic cal certificate protocol pressure</p>          </td>       </tr>       <tr>          <td>             <p>kq=<input id="varkq" type="text"></p>          </td>          <td>             <p>tn34013 ic cal certificate protocol tw30 beam quality correction value</p>          </td>       </tr>       <tr>          <td>             <p>kak->dw=<input id="varkak" type="text">          </td>          <td>             <p>correction factor tn 34013 ic  ptw. air kerma --> absorbed dose water convertion tw30 water phantom manual pg43</p>          </td>       </tr>       </p>       <p><input type="button" value="calculate step 1" onclick="docalcone()"></p>       <p><input type="button" value="calculate step 2" onclick="docalctwo()"></p>    </table>    <br>     </html> 

edit 2: working function:

    function docalcone() {     var varnk = document.getelementbyid('varnk').value;         var varqr = document.getelementbyid('varqr').value;        var vart = document.getelementbyid('vart').value;     var varto = document.getelementbyid('varto').value;     var varpo = document.getelementbyid('varpo').value;     var varp = document.getelementbyid('varp').value;     var varkq = document.getelementbyid('varkq').value;     var varkak = document.getelementbyid('varkak').value;      var result1 = document.getelementbyid('stepone');     var stepone = varnk * (math.pow(10,9)) * varqr * (math.pow(10,-12)) * ( 273 + vart ) / ( 273 + varto ) * varpo / varp * varkq * varkak;      num = stepone;     result1.value = num.toprecision(4); } 

call docalctwo function @ end of docalcone, passing along variables need, , should expect! can nuke 2nd button have well. here's updated code:

update: made 1 function , added think correct math. don't have clue you're trying calculate excel-style math can translate on javascript one-to-one. order of operations you!

function docalcone() {     var varnk = document.getelementbyid('varnk').value;         var varqr = document.getelementbyid('varqr').value;        var vart = document.getelementbyid('vart').value;     var varto = document.getelementbyid('varto').value;     var varpo = document.getelementbyid('varpo').value;     var varp = document.getelementbyid('varp').value;     var varkq = document.getelementbyid('varkq').value;     var varkak = document.getelementbyid('varkak').value;      var result1 = document.getelementbyid('stepone');     var stepone = varnk * varqr * ( 273 + vart ) / ( 273 + varto ) * varpp / varp * varkq * varkak;      result1.value = stepone; } 

honestly, don't need 2 functions here assume have/had reasons break that. know can combine these functions 1 , should work.

another point i'd make variables create inside 1 function not available different function. called "scope" , determined looking @ opening/closing curly brackets ({ , }). poorly formatted code makes harder keep track of ;).


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -