PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Dropdown list + Selected value

  1. I am trying to customize the walkthrough for Tax (http://gravityhelp.com/documentation/page/Gravity_Forms_Pricing:_Adding_Tax).
    But in my case, I want the tax rate to vary based on a preselected item from a dropdown list.
    So for example
    if you selected option 1 from the specified dropdown, then ur tax rate is X%, if you selected 2, your rate will be Y% etc.
    How do I use/call up the value/item in the selected field? What filter/function/code can I use to acieve this?

    See part of what I have so far in my functions.php

    add_filter('gform_pre_render_3', 'add_total_script');
    	function add_total_script($form) {
    	    ?>
        <script type="text/javascript">
       	 function gform_product_total(formId, total){
             var rate = 0;
    	if ($(".ginput_3_20 option:selected").text()) == "Option1_selected"){
            rate = 20; } else {
            if ...................................// an so on
            } else {
            rate = 100;
            }  //end if
            var tax = ((rate * total) / 100);  //calculate the tax to be paid and add below;
            return total + tax;
        }
        </script>
    
    <?php
        return $form;
    }
    Posted 12 years ago on Tuesday February 7, 2012 | Permalink
  2. Give this a shot: http://pastie.org/3350499

    Be sure to update as indicated by the comments. :)

    Posted 12 years ago on Thursday February 9, 2012 | Permalink
  3. Works Great. But How do I 'monitor' the dropdown, should the user change it.
    The form calculates based on the selection, but doesnt update if for instance I go back and change the value in the dropdown.
    Regards,

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  4. Hi VAR,

    Here is an adjusted snippet where we let Gravity Forms know that any time the drop down changes it should recalculate the form:

    http://pastie.org/3360358

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  5. It kind of did not work.
    Here is what I have. http://www.pastie.org/3360944
    The other one worked better except the lack of communicating change in selection. Any ideas?

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  6. My select field was hidden (displays on a condition), I undid that (made it visible) and still not working....

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  7. Ok I think I got it to work.
    Check http://www.pastie.org/3361172
    I changed
    taxRateField.change(function(){
    to
    jQuery(document).ready(function(){
    jQuery('select#input_3_21').bind('change', function(){
    Removed the - var taxRateField = jQuery('select#input_3_21'); and referred to it directly as jQuery('select#input_3_21') in all instances
    Then somewhere along I keep displaying the rate, to verify that it changes and let the user know.

    I hope it continues to work. Any redundant line or better way?

    Thanks y'all

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  8. Sounds like you got it. :)

    Posted 12 years ago on Monday February 13, 2012 | Permalink
  9. Now left with one other issue: THE BACKEND TOTAL
    For the backend total, GF Example used a fixed figure, 20, how can I incorporate the tax value (based on selection).

    add_filter('gform_product_info_78', 'update_product_info', 10, 3);
    function update_product_info($product_info, $form, $entry) {
    $total = get_total($product_info);
    $tax = (20 * $total) / 100; // update the "20" to the desired tax percentage
    .........

    how do I change that '20' to pick the tax value?
    Thanks

    Posted 12 years ago on Tuesday February 14, 2012 | Permalink
  10. Got this working myself, just need help with this topic
    http://www.gravityhelp.com/forums/topic/validating-form-read-only-fields-and-pre_render-hook
    Thanks

    Posted 12 years ago on Tuesday February 28, 2012 | Permalink