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
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    when i use onKeyUp for few hundred of text box, slow....

    dear,

    when i use onKeyUp for few hundred of textboxes, the respond will a bit slow...

    example: when user key in a number in "textbox1" i will onkeyup to do some calculationwith the number, then the new value will show on the next text box : "amt1", for "textbox2" if user key in a number on "amt2" will do calculation and new calculated value may display.

    if for hundred of textbox will a little slow respond... how to slow the problem?

    here are 1 of the sample, im using asp to loop hundred times...

    <input type=text name=textbox1 onkeyup="sumtotal(this.form,1); updatetotal()">
    <input type=text name=amt1 value=0.00>

    <input type="text" name="total" size="15" value="">

    <SCRIPT language=JavaScript>
    function roundoff(amount) {
    return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
    }

    function sumtotal(what,kk) {
    var kk
    var what
    for(var i=0;i<kk;kk++){
    var num = what.elements['textbox'+kk].value;
    var uom = what.elements['amt'+kk].value;
    var subtotal = num * uom
    var subtotal = roundoff(Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2));
    return what.elements['amt'+kk].value = subtotal;
    }
    }

    function updatetotal(num) { // For me i think here will be the main problem, bcos here will generate many rows of "parseFloat(document.form1.amt1.value)+parseFloat(document.form1.amt2.value)+......parseFloat(docume nt.form1.amt300.value)"
    var sum=0
    var sum=
    <%
    dim intcounter
    FOR intcounter = 1 to (cccc-1)
    response.write "parseFloat(document.form1.amt"&intcounter&".value)"
    if (intcounter<(cccc-1)) then
    response.write "+"
    end if
    NEXT
    %>
    sum = roundoff(Math.round(sum*Math.pow(10,2))/Math.pow(10,2));
    document.form1.total.value=sum
    }
    </SCRIPT>
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    it will really be slow since you have a hundred fields to update for every keystroke of the user. I suggest you don't do it onkeyup but have a button that will update the fields or do it onblur.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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