The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

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">
	// 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('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;

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

Can someone help me get this to work? Thanks in advance!
  • 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.