var postageOptions = []; $('#promoEmail').focusout(function() { if(validateEmail($('#promoEmail').val())){ catchEmail(); $('#cardEmail').val($('#promoEmail').val()); } }); $('#promoOpt').change(function() { if(validateEmail($('#promoEmail').val())){ catchEmail(); } }); function validateEmail(email) { var re = /^(([^<>()\[\]\.,;:\s@"]+(\.[^<>()\[\]\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } $('#paypalform').submit(function() { if(validateEmail($('#promoEmail').val())){ return true; }else{ alert('Please enter a valid email'); return false; } }); $('#cardForm').submit(function() { if(validateEmail($('#promoEmail').val())){ return true; }else{ alert('Please enter a valid email'); return false; } }); function catchEmail(){ var url = './functions/mailchimp.php?email='; url = url + $('#promoEmail').val(); if ($('#promoOpt').is(':checked')) { url = url + '&opt=1'; }else{ url = url + '&opt=0'; } console.log('calling: ' + url); $.get( url , function( data ) { console.log(data); }); } landUpdateShipping(); $('#shipTo').change(function() { updateShippingPrice(); }); function updateShippingPrice(){ var totalLessShip = ; var s = document.getElementById('shipTo'); var des = s.options[s.selectedIndex].value; var freeJSpostagePrice = ; console.log(des); if(des+0 == 8){ document.getElementById('payPost').value = '0'; }else{ var shippingPrice = postageOptions[des].cost; document.getElementById('payPost').value = shippingPrice; document.getElementById('shipCost').innerHTML = ''+shippingPrice.toFixed(2); var gTotalTrailing = ''+(shippingPrice+totalLessShip).toFixed(2); document.getElementById('grandTotal').innerHTML = gTotalTrailing; } document.getElementById('cardShip').value = des; } function landUpdateShipping(){ var s = document.getElementById('shipTo'); var freeJSpostagePrice = ; if(freeJSpostagePrice){ s.value = 8; } updateShippingPrice(); }