[thelist] Javascript orderform speed issue
Matt Warden
mwarden at gmail.com
Sun Mar 5 03:12:57 CST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Rory Lysaght wrote:
> I've got a large order form that uses script to update the subtotal
> automatically as soon as you enter a quantity. The page itself is
> pretty large - about 1050 products in about 11 tables. I'm working on
> slimming down that code. But the problem I have is the speed of
> updating the page subtotal. Every time someone enters a number in the
> quantity field, I need to loop through all 1050 fields to update the
> page total. In Firefox it's really zippy, but in IE6/Win it's
> incredibly slow. I'm guessing on older /slower PCs it's almost
> unusable. I've optimized the Javascript as much as I can, but I'm
> wondering if anyone can explain why it's radically slower in IE, or
> suggest a faster way to do this?
> You can see the form here: http://memoryboxco.com/orderform.htm
There's no need to go through every field. Only the ones the user has
touched.
Something like...
var touched = {};
window.onload = function()
{
var inputs = document.getElementsByTagName('input');
for (var i=0; i<inputs.length; i++) {
inputs[i].onchange = markTouched;
}
}
function markTouched(e)
{
e = e || window.event;
var input = e.srcElement || e.target;
var id = input.id;
touched[id] = input.value;
}
function updateTotal()
{
var totalinput = ...;
// ...
// use the object touched = {id: value, id: value, etc.}
// to calculate total. you don't really need to revisit
// the actual input fields at this point.
// ...
}
window.setInterval("updateTotal();", 800);
- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFECquZrI3LObhzHRMRAkFCAKDBEvqkqrOuditbLNcDaBUxQmo34QCgnmhT
m/uYHFzHaX0O7IGH8om7hME=
=Z7vz
-----END PGP SIGNATURE-----
More information about the thelist
mailing list