...

View Full Version : when i use onKeyUp for few hundred of text box, slow....



NinjaTurtle
02-28-2003, 03:19 AM
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(documen t.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>

glenngv
02-28-2003, 03:33 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum