> From: Dan Eastwell
> I'm doing an order form for a bookstore. The order form has 
> over 500 items in it, so jquery runs slowly...

Can't you do any of this on the server? All of the code generation - the IMG
tags and the zebra striping - would cost next to nothing while the page is
being generated on the server. And if the page is gzipped it wouldn't even
take much extra download time.

Then, instead of binding event handlers to all of the individual buttons,
just bind a single event handler to the parent form:

   $('#order_form').click( function( event ) {
      var $target = $(event.target);
      if( $target.is('img.increment') ) return change( 1 );
      if( $target.is('img.decrement') ) return change( -1 );
      
      function change( by ) {
         var $qty = $target.parent('td').find('[EMAIL PROTECTED]');
         var n = +$qty.val() + by;
         if( n >= 0 ) $qty.val( n );
         return false;
      }
   });

Even if you have to do the code generation in JavaScript, you can use this
technique to eliminate all the individual event binding and cut the
JavaScript load time overhead to virtually nothing.

Let us know if the JavaScript code generation is really mandatory - I saw
the other replies but there are still a few remaining tricks to speed it up.

-Mike

Reply via email to