Client-side form validation : Calling the cart from Javascript

mbowzeylombowzeylo Member
in Help edited December 2007
My client wants to sell Gift Certificates and let the customer enter the gift certificate amount themselves... eg they can enter $70, or $155, or $500, etc.

They also want to set a minimum of $50. So on the FoxyCart form field for "price" I let the user enter their own amount into the text field. No problems so far!

I want to use a tid bit of JavaScript to validate that the amount is $50 or more. If it isn't it sends an alert box, if it is $50 or more then it calls the cart. Again, no problems so far.

Here is my code:

Instead of a submit button, I have a link that calls a javascript function:
<a href="javascript: storeCheckForm()"><strong>BUY NOW</strong></a>

Now here is the storeCheckForm() function:
function storeCheckForm(){
	if (document.gcForm.price.value <=49.99){
		alert("Minimum $50 required.");
		document.gcForm.price.focus();
	}
	if (document.gcForm.price.value >=50){
		document.gcForm.submit();
	}
}

Now here is my problem... my script works as intended except that when the cart is called it leaves out the class="foxycart" so it does not open in the thickbox.


Does anyone have any suggestions of how to fix this? You help is very much appreciated.

Mike
Comments
  • brettbrett FoxyCart Team
    Hi Mike.
    What you might want to do is make your storeCheckForm() part of fc_PreProcess(), which gets called before the foxybox actually loads.

    http://wiki.foxycart.com/docs:json

    If you return false, the cart won't load, which I think is what you want, right? Error, but _don't_ load cart. (Your link doesn't work so I can't test for sure myself.)
  • Sweet... now I can just put any validation I need to perform inside that function. It works perfectly. That was exactly what I wanted to do. Thanks Brett.
Sign In or Register to comment.