now to make sure they donate at least $1

mwinsteinmwinstein Member
in Help edited September 2008
Hi,

I'm trying to get a new donation form set so people enter not less than $12.00 during a 12 month period.

As you can see, people can opt for the total amount they want to give, and how often.

I'd like to keep the amount box totally free form. Last time I experimented with this approach, one person donated $100 a month.

I'd like to be able to handle this with JSON, where it would multiply the gift times the number of periods in a year to get a total that needs to be at least $12.

Can you set me in the right direction? I'm not finding enough info on the JSON objects to build from the last success we had with forcing a minimum quantity.

Thanks!

Mark
Comments
  • brettbrett FoxyCart Team
    I'd do it pre-add-to-cart, so on your form itself. That way you (conceivably) don't have to mess with the JSON on the cart.
    $j('#form_id').submit(function(){
    if (($j('#amount).val() * $j('#frequency').val()) < 12) {
    alert("Please donate at least $12 per year");
    return false;
    }
    });
    

    Something like that. Might depend on what your frequency field looks like (doing subscriptions?), might have to translate the 1m or 1y or 3m or whatever values into a number to make your math work, but that's how I would handle it.
  • hi

    I get the point, but I'm not too familiar with the syntax using "$j" etc., although I've used javascript elsewhere.

    Here's where I'm at.

    I wrote a very dumb function just to see if I could call it from the form:

    <form ....

    <script language="javascript">
    $j('#gscform').submit(function(){
    alert("Please donate at least $12 per year");
    return false;
    });
    </script>

    </form>

    This proved that I could call an alert box. However, the "return false" didn't seem to function and the cart opened up.

    All I really need here is enough code to show me how to pull the value of the field named "price" into an alert box, and also show that I can get the form to return false and not go to the cart. I can probably take it from there...

    Thanks!

    Mark

    <input name="price" type="text" value="" size="10" maxlength="10" />


    I get that I can plant this code in my form. I was able to
  • brettbrett FoxyCart Team
    Oh, you're totally right. Returning false wouldn't work because of how foxycart_includes.js is doing things.

    You'd need to do this:
    function fc_PreProcess() {
    if ($j('#amount).val() < 12) {
    alert("Please donate at least $12 per year");
    return false;
    }
    }
    

    Make sure you get familiar with jQuery, which is what FoxyCart uses by default (and is packaged in the foxycart_includes.js file): http://docs.jquery.com/Tutorials

    jQuery is usually called with $(), but by default in FoxyCart it's remapped to $j() for increased compatibility with other libraries.
  • mwinsteinmwinstein Member
    edited September 2008
    I've got a working function (please take a look: http://club.ecosector.com).

    BUT...

    it runs twice each time it's called!!

    Any ideas on that?

    Thanks!

    Mark

    P.S. - I have the function set to return false in every case during this testing phase...
  • brettbrett FoxyCart Team
    Huh... that's a good question, and I'm not seeing anything that jumps out at me as the cause...

    I don't think it's a bug on our end, but there's definitely something weird. It's probably something tiny that I'm missing.

    Have you tried stripping the page down to just the form, the function, and the FoxyCart files? I'd strip it down to the basics and see if you get the same problem.
  • lukeluke FoxyCart Team
    Hey Mark, remove this from your form tag:
    onsubmit="fc_PreProcess();"
    
  • brettbrett FoxyCart Team
    Dang, I knew it was something simple! Totally missed that. Good catch, Luke.
  • that's really great. it works great. thanks!
Sign In or Register to comment.