Skip to content

Instantly share code, notes, and snippets.

@rickycheers
Created November 27, 2012 23:55
Show Gist options
  • Save rickycheers/4158041 to your computer and use it in GitHub Desktop.
Save rickycheers/4158041 to your computer and use it in GitHub Desktop.
Minimum Amount 2D Forms
// copy and paste this code into your page source inside <script></script> tags
(function($){
$(document).ready(attachEvent);
function attachEvent(){
minimum_amount = 1; //update this
$form = $('form#commerce_3'); //update this
$overlay = $('#overlay');
$processing = $('#processing');
$custom_radio_button = $('#frmItem_130_347'); //update this
$custom_donation_input = $('#donation_value_103_347') //update this
$form.one('submit', function(e){
e.preventDefault();
$overlay.hide();
$processing.hide();
if( $custom_radio_button.is(':checked') ){
custom_donation = $custom_donation_input.val();
custom_donation = parseInt(custom_donation);
if( custom_donation != NaN && custom_donation >= minimum_amount ){
$overlay.show();
$processing.show();
$form.submit();
} else {
$('#error_message').remove();
$error_message = $('<div id="error_message" class="error">The minium amount is $'+minimum_amount+' USD</div>');
$custom_donation_input.parent().after($error_message);
attachEvent();
}
} else {
$form.submit();
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment