Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

+/- buttons for qty boxes


Guest

Recommended Posts

Posted

I'm looking for a way create some + and - buttons for the quantity boxes on my site. I found this code but can’t get it to work. Is it suitable for osccomerce? If so where do I put it (html_output, index)? Help appreciated:

 

function setQuantity(pcID, pnOperation, pnMin, pnMax)
{
var lnCurrentQuantity = parseInt(document.getElementById(pcID).value);							  
var lnNewQuantity	 = lnCurrentQuantity;
switch(pnOperation)
{				  
	case 1: // increase quantity by 1
		lnNewQuantity++;
		if(lnNewQuantity > pnMax)
		{								
			lnNewQuantity = lnCurrentQuantity;
		}
		break;
	case 2:// decrease quantity by 1
		lnNewQuantity--;
		if(lnNewQuantity < pnMin)
		{
			lnNewQuantity = lnCurrentQuantity;
		}
		break;
	default:// ensuring a typed quantity remains within the parameters defined
		if (lnCurrentQuantity > pnMax || lnCurrentQuantity < pnMin)
		{									
			alert("Please set the quantity as a number between " + pnMin + " and " + pnMax + '\n' + "The quantity will now be set to " + pnMin);
			lnNewQuantity = pnMin;
		}
		break;
}

document.getElementById(pcID).value = lnNewQuantity;
}

 

 

<!-- reduce quantity -->
<img src="image/minus.png" alt="minus" title="Decrease Quantity" onmouseover="this.style.cursor=\'pointer\';" onclick="setQuantity(\'dataQuantity\', 2, 1, 6);"/>
<!-- the input box -->
<input class="quantity" type="text" id="dataQuantity" name="dataQuantity" value=1 onblur="setQuantity(\'dataQuantity\', 3, 1, 6);"/>
<!-- increase quantity -->
<img src="image/plus.png" alt="plus" title="Increase Quantity" onmouseover="this.style.cursor=\'pointer\';"  onclick="setQuantity(\'dataQuantity\', 1, 1, 6);"/>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...