Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(document).ready(function(){
- // when enter coupon code text, update the coupon amount field accordingly
- // 'Allow field to by dynamically populated' must be checked in form field editor
- // to allow for negative values. no parameters needed.
- $('#input_3_18').bind("input",function(){
- var form_id = 3; // which form
- var field_id = 17; // coupon AMOUNT field
- var coupon = $(this).val(); // coupon text code field value
- var minlength = 4; // minimum length of coupon code before start checking
- var ajaxpath = 'http://www.yoursite/wp-admin/admin-ajax.php';
- var adminLabel = 'coupon_codes';
- if(coupon.length > minlength){
- // clear the value of the coupon amount
- $("#ginput_base_price_"+form_id+"_"+field_id).val(0);
- $("span#input_"+form_id+"_"+field_id).html("-$0.00");
- // update the form total price
- gformCalculateTotalPrice(form_id);
- // indicate that the form is thinking
- $(".ginput_total").append('<span id="loading"> ...validating</span>');
- fieldchoices = '';
- // retrieve a list of valid coupon codes, ajax function in functions.php
- $.ajax({
- url:ajaxpath,
- type:'POST',
- data:'action=getchoices_fromfield&adminLabel='+adminLabel+'&form_id='+form_id,
- success: function(results) {
- // get an array of choices
- fieldchoices = $.parseJSON(results);
- $.each(fieldchoices, function(index, obj) {
- // case insensitive comparison of entered code and valid codes
- if(coupon.toLowerCase() == obj.text.toLowerCase()){
- // update the coupon amount input field
- $("#ginput_base_price_"+form_id+"_"+field_id).val(-obj.value);
- $("span#input_"+form_id+"_"+field_id).html('-$'+obj.value);
- // update the form total
- gformCalculateTotalPrice(form_id);
- }
- });
- }
- });
- $("#loading").fadeOut(5000);
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement