/    Sign up×
Community /Pin to ProfileBookmark

Math equation, pls help.

I have the following code which is for a math equation:
S / the total sum of I.

And i have 2 questions here:
1. The current code can only allow me to calculate the total sum of ‘I’, THEN need to manually key in the result of ‘Itotal’ and divide by ‘S’ in another form. How can i make it into one form where i just need to key in the value of ‘S’ and all the values of ‘I’, then click on ‘calculate’?

  • 2. I need to do another equation which similar to this, but with a power of ‘-n’ for both the ‘S’ and ‘I’ value. (ie: S power -n / total sum of I power -n)
  • Your help is greatly appreciated.

    [CODE]
    <html>
    <head>
    <title>Form</title>

    <script type=”text/javascript”>

    function addRowToTable()
    {
    var tbl = document.getElementById(‘tblSample’);
    var frm=document.form0;
    if (!frm.ary) frm.ary=[frm.t1_2];
    var lastRow = tbl.rows.length;
    // if there’s no header row in the table, then iteration = lastRow + 1
    var iteration = lastRow + 1;
    var row = tbl.insertRow(lastRow);

    // numberd row, 1 2 3
    var cellLeft = row.insertCell(0);
    var textNode = document.createTextNode(iteration);
    cellLeft.appendChild(textNode);

    // Participant row
    var cellRight1 = row.insertCell(1);

    // Price row
    var cellRight2 = row.insertCell(2);
    var el2 = document.createElement(‘input’);
    frm.ary.push(el2);
    el2.size = 15;
    el2.onkeyup=Calc;
    //el2.onblur=Calc;
    cellRight2.appendChild(el2);

    }

    </script>

    <script type=”text/javascript”>

    function Calc(){
    var frm=document.form0;
    //if (!frm.ary) frm.ary=[frm.t1_2];
    var total=0;
    for (var zxc0=0;zxc0<frm.ary.length;zxc0++){
    if (frm.ary[zxc0].value.length>0&&!isNaN(frm.ary[zxc0].value)) total+=frm.ary[zxc0].value*1;
    }
    frm.sum.value=total;
    }
    </script>

    <script type=”text/javascript”>
    function SI()
    {
    var s = document.first.S.value;
    var i = document.first.I.value;

    var final= 0;

    var final = (s/i);

    document.first.si.value = final;
    }
    </script>

    </head>
    <body>
    <table border=”0″ align=”center” width=”200″ style=”border:1px dashed #000000;” cellpadding=”0″ cellspacing=”10″ id=”tblSample”>
    <form action=”none” method=”get” name=”form0″ id=”form0″>
    <td width=”50″>1</td>

    <td></td>
    <td width=”100″ height=”40″><input type=”text” name=”t1_2″ id=”t1_2″ size=”15″ value=”” onkeyup=”Calc();”>
    </td>
    </tr>
    </table>
    <br>
    <table border=”0″ align=”center” width=”200″>
    <tr>
    <td width=”400″ style=”text-align:center;”><form method=”get” name=”form0″ id=”form0″>
    <input class=”button” type=”button” value=”Add” onclick=”addRowToTable();Calc();”></td>
    <td width=”100″ style=”text-align:left;”> I<sub>Total</sub>:</td>
    <td width=”100″ style=”text-align:center;”><input type=”text” name=”sum” id=”sum” size=”4″ onkeyup=”Calc();”></td>

    </tr>
    </table>

    </form>

    <table border=”0″ align=”center” width=”200″ style=”border:1px dashed #000000;” cellpadding=”0″ cellspacing=”10″>
    <tr><td align=center >

    <form name=first>
    <table cellspacing=0 cellpadding=3>
    <tr><td>S:</td><td><input name=S type=text size=15 onkeyup=checnum(this) ></td></tr>
    <tr><td>I<sub>Total</sub>:</td><td><input name=I type=text size=15></td></tr>

    </table>
    <br><input type=button name=ss value=calculate onclick=SI() class=calc>
    <br>

    <table cellspacing=0 cellpadding=3>
    <tr align=center><td class=inner colspan=2><b>Results:</b></td></tr>
    <p></p><tr><td>S/I:</td><td> <input name=si type=text readonly > </td></tr>

    </td></tr>
    </table></form>

    </table>

    </body>
    </html>[/CODE]

    to post a comment
    JavaScript

    0Be the first to comment 😎

    ×

    Success!

    Help @kerene spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...