LightCMS Form Help

fc_joshfc_josh FoxyCart Team
in Help edited June 2010
I have read the related article for LightCMS forms. I am trying to modify the javascript so I can have a field for quantity. Below is the javascript code I have placed in the HEAD of my website:
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
	// Set the event for all input[name=price] fields inside of div.form elements
	jQuery('div.form input[name=price]').change(function(){
		// Find and set the elements
		var this_form = jQuery(this).parent('div.form')[0];
		var this_link = jQuery(this_form).children('a')[0];
		var price = jQuery(this).val();

		// Strip out the $ in case the user adds it, and format it as a currency
		price = price.replace('$', '');
		price = parseFloat(price);
		price = fc_CurrencyFormatted(price);
		jQuery(this).val(price);

	jQuery('div.form input[name=quantity]').change(function(){
		// Find and set the elements
		var this_form = jQuery(this).parent('div.form')[1];
		var this_link = jQuery(this_form).children('a')[1];
		var quantity = jQuery(this).val();
 
 
		// Replace the current price in the add-to-cart link with the newly entered price
		if (parseFloat(price)) {
			var this_href = jQuery(this_link).attr('href');
			var this_href_new = this_href.replace(/price=[0-9.]+/, 'price='+price);
			jQuery(this_link).attr('href', this_href_new);

		if (parseFloat(quantity)) {
			var this_href = jQuery(this_link).attr('href');
			var this_href_new = this_href.replace('quantity='quantity);
			jQuery(this_link).attr('href', this_href_new);

		} else {
			alert('Please enter a numeric value for your donation.');
			return false;
		}
	});
});
</script>

Below is the HTML code:
<input type="text" name="quantity" value="1" />
<a href="https://myaccount.foxycart.com/cart?name=Product Name&amp;price=5.00&amp;quantity=" class="foxycart">Add to Cart</a>

Can someone help me get this to work? Thanks in advance!
Comments
  • brettbrett FoxyCart Team
    Can you share the URL where you're attempting this? That'll make it a lot easier to troubleshoot. You can whisper if it's private.
Sign In or Register to comment.