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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    totaling a form ---- URGENT HELP

    Hi

    I got this script from the forum..


    Code:
    <!--
    
    function getVal(){
    
    var doc = document['oFrm'];
    
    doc['tot'].value = ((doc['AMT1'].value)/1) + ((doc['AMT1'].value)/1);
    }
    }
    //-->
    </script>
    
    .........
    
    Print("<form METHOD=\"POST\" ACTION=\"index2.html\" name=\"oFrm\">\n");
    
    .......
    
    <input type=\"textbox\" size=\"5\" id=\"AMT$i\"  name=\"AMT$i\"  size=\"12\" onkeyup=\"javascript:getVal();\" onkeydown=\"javascript:getVal();\">
    ...
    <input id=\"tot\" name=\"tot\" size=\"12\" readonly></font>
    </form>
    This scvript works for the first two text boxes in the form.

    What modification would I need to do so that lets say I have 26 text boxes that need to be totaled...amt1,amt2...amt26...

    I know a for loop would be good but I have tried adding a for loop and i keep getitng it worng.. getting things concatinated instead of adding things up...


    Need some very urgen help...i know its simple but i think i am not too familiar with the rules of javascriting/c++ hence a poblem implimenting or chnigng the script.

    Thanks
    Apurva

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    solved to certain extent

    <script language="javascript">
    function addAll(){
    var frm = document.form;
    var len = parseInt(frm.count.value);
    var total = 0;
    for (var i=1;i<len;i++){
    objNum = eval("frm.num"+i);
    total+=parseFloat(objNum.value);
    }
    frm.tot.value=total;
    }
    </script>

    ............

    Print("<form METHOD=\"POST\" ACTION=\"index2.html\" name=\"f\">\n");
    <input type=\"hidden\" name=\"count\" value=\"$numrows\">
    <input name=\"tot\" size=\"6\" value=\"00.00\" onfocus=\"this.blur()\" readonly>
    While ($row2 = MYSQL_FETCH_ARRAY($r2)){
    <input type=\"textbox\" size=\"5\" id=\"Amt\" name=\"AMT$i\" value=\"00.00\" onblur=\"if (isNaN(this.value)) this.value='00.00'\" onchange=\"addAll()\">
    }




    I got this code from Glenn and well modified it slighly and it seemed to work...
    the next problem is how do i check the value in tot against a another value in the form (got from the DB) called Balance and if the value in tot is greater than the value in Balance then the submit button at the end of the form disappears.


    Any ideas ??

    thanks
    Apurva


  •  

    Posting Permissions

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