I have this on click function, that I need to add another function inside of to do a pause and finish, and then resume the onclick function to continue.
-function to call and pause : errorCheckingOrder(). see below
Here is function onclick:
$('#payment_submit_order').on('click', function(){
errorCheckingOrder();//here is the function calling it
var data = {fName : $("#returnfirstName").val(), lName: $("#returnlastName").val(), add1: $("#returnaddress1").val(), add2: $("#returnaddress2").val()};
data.city = $("#returncity").val();
data.state = $("#returnstate").val();
data.mail = $("#returnemail").val();
data.zipcode = $("#returnzipcode").val();
var returnAddress = saveAddress(data);
var value = $('input[name=shippingType]:checked').val();
if(value == 0){
var address = saveAddress();
var shipping = ($('input[name=shippingmethod]:checked').val()*productCart.length).toFixed(2);
for(var i in productCart) {
productCart[i].addressId = address;
productCart[i].shippingmethod = shipping;
productCart[i].returnAddress = returnAddress;
}
}else{
for(var i in productCart) {
var address = $("#selectProductAddress_"+productCart[i].uProductID).val();
productCart[i].addressId = address;
productCart[i].returnAddress = returnAddress;
var shipping = 0;
$('input[name^="shippingmethod_"]').each(function(){
if($(this).is(":checked")){
shipping += parseFloat($(this).val());
}
});
shipping = shipping.toFixed(2);
productCart[i].shippingmethod = shipping;
}
}
});
And here is the function for doing the error checking/validations. Which we need to go thru first, then once good. Continue. the function above.
I would put the error_checking in a second function, then return a value to your click handler, so that it can decide how to proceed:
function checkForErrors(){
// all of your error checking goes here
//
// return a truthy or falsey value indicating success or failure
}
$('#payment_submit_order').on('click', function(){
var validSubmission = checkForErrors()
if validSubmission{
// do this
} else {
// do that
}
});
Our Error Checking live on our HTML page, the submit function live on our jquery code.
We tried having it call the error checking function, on submit, see code below. But that does not work. Can you help up combine the two to function correctly.
Here is our current code, the validation check function
isValCheckingShipping();
Get kicked -off on submit, that works. All the required fields show error and fields need to filled in.
Once all fields are filled thou, You click Submit and it does not continue, it reload the page with, like it starting the isValCheckingShipping(), error checking all over again, what condition should we write so it can continue on submission of form
$( "#payment_submit_order" ).submit(function(e) {
if(isValCheckingShipping() === false){
e.preventDefault();
} else {
//else the submit will pe performed
//});
var data = {fName : $("#returnfirstName").val(), lName: $("#returnlastName").val(), add1: $("#returnaddress1").val(), add2: $("#returnaddress2").val()};
data.city = $("#returncity").val();
data.state = $("#returnstate").val();
data.mail = $("#returnemail").val();
data.zipcode = $("#returnzipcode").val();
var returnAddress = saveAddress(data);
var value = $('input[name=shippingType]:checked').val();
if(value == 0){
var address = saveAddress();
var shipping = ($('input[name=shippingmethod]:checked').val()*productCart.length).toFixed(2);
for(var i in productCart) {
productCart[i].addressId = address;
productCart[i].shippingmethod = shipping;
productCart[i].returnAddress = returnAddress;
}
}else{
for(var i in productCart) {
var address = $("#selectProductAddress_"+productCart[i].uProductID).val();
productCart[i].addressId = address;
productCart[i].returnAddress = returnAddress;
var shipping = 0;
$('input[name^="shippingmethod_"]').each(function(){
if($(this).is(":checked")){
shipping += parseFloat($(this).val());
}
});
shipping = shipping.toFixed(2);
productCart[i].shippingmethod = shipping;
}
}
$.cookie(cart_cookie_name, $.toJSON(productCart));
var productAddress = {};
var retriveAdd = $.cookie(address_cookie_name);
if(retriveAdd != null){
productAddress = $.parseJSON(retriveAdd);
}
//MG.01.2014
//Menu Location and Link Back to Store Controlled menu
//Shipping Information Menu active and completed tasks
var shippingmenu = $('.progress-bar .step.active h4').html();
alert(shippingmenu);
/******************Session Array Integration (SAI) - Update********************/
//Posting to Backend Session Kick Off
//MG. added
//AJAX>JSON posting for shipping details
//This loads the indidivual shipping information and updates it to
//Session and DB for java.controllers
//See combine productCart & productAddress Details updated
var dataString = {product:JSON.stringify(productCart), address: JSON.stringify(productAddress)},
loadUrl = '/shipping';
$.ajax({
type: 'POST',
url: loadUrl,
data: dataString,
complete: function(data){
window.location = "./checkout/payment.html";
},
error:function(data) {
alert("error: "+data);
}
});
}
});