Skip to content Skip to sidebar Skip to footer

Php Generated Textbox Operation With Javascript

I'm using text boxes to let users change the quantity in a ecommerce website, e.g., http://nordschleife.metaforix.net/118/118/index.php/sony.html There are two problems that I hope

Solution 1:

1: Instead of registering an event for every arrow separately you can make only one script for all of them. Make an arrow look like this:

<a id="upImg_705" ... rel="qty_705"class="uparrow">
<inputid="qty_705"class="input-text qty"type="text" value="1" maxlength="12" name="qty"/>
<a id="downImg_705" ... rel="qty_705"class="downarrow">

an then register these functions as click event handlers:

$('.uparrow').live("click", function() { 
   var rel = $(this).attr('rel');
   var textbox = document.getElementById(rel);
   textbox.value = parseInt(textbox.value)+1;
   returnfalse;
}
$('.downarrow').live("click", function() { 
   var rel = $(this).attr('rel');
   var textbox = document.getElementById(rel);
   textbox.value = parseInt(textbox.value)-1;
   returnfalse;
}

2: To prevent goin to the top of the page use href="javascript:void(0);" instead of href="#" in your links. Alternatively your onclick method might return false to prevent default action (i.e. changing the location of your web page).

Solution 2:

  1. Use jQuery's live() to create events that will be re-applied when the page is changed via an AJAX update.
  2. event.preventDefault() will stop this.

Post a Comment for "Php Generated Textbox Operation With Javascript"