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.

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.");
	if (document.gcForm.price.value >=50){

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.

  • 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.

    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.