Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Will this code work in oscommerce?


Guest

Recommended Posts

Found this code via google for enabling increments and decrements to numeric values in qty boxes via images (+ and - buttons basically). This is what I'm looking to do for the qty boxes on my site but don't know if its suitable for oscommerce ?

 

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);"/>

 

 

Anyone know if it will work or where I have put it in order to establish if it works? I tried putting the first part in html_output but after that none of the pages would load. All suggestions welcome. Thanks.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...