SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    vi
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy how to get the function to execute validations function & then continue?

    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:
    Code:
                $('#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.
    Code:
    	
    			//Personlize & Customize Validation placed here
    			$(function errorCheckingOrder(){
    				bindValidation("shipping_gift_card","${pageContext.response.locale}");
    				$("#payment_submit_order").click(function(){
    					return isValidation("shipping_gift_card","${pageContext.response.locale}");
    				});
    			});
    Please help how we get, the validations to go thru first, then run the payment_order on click function????

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by danjapro View Post
    Please help how we get, the validations to go thru first, then run the payment_order on click function????
    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:

    Code:
    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
      }
    });

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    vi
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why we did not see this, we will try your code and it seems to be down the path we are hoping will work..

    Code:
          $( "#form_id" ).submit(function( event ) {
            if(yourValidationFunction() === false){
          event.preventDefault();
            }
         //else the submit will pe performed
        });

    Thank you, we will update as we test away.


    Quote Originally Posted by Pullo View Post
    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:


    Code:
    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
      }
    });

  4. #4
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    vi
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Pullo, Please guide use

    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.



    Quote Originally Posted by Pullo View Post
    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:

    Code:
    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
      }
    });

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    vi
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question error validations function working but NOT continuing to submit form once all filled!

    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


    Code:
     $( "#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);
    				    }
    				});
    			}	
    		});

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Can you post a link to your page?

  7. #7
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    vi
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Go thru to see

    Quote Originally Posted by Pullo View Post
    Can you post a link to your page?
    See if you can access thisL https://givevanillagift.incomm.com/store/

    Go thru purchasing to get to shipping page, where the validations is taking place.

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by danjapro View Post
    See if you can access thisL https://givevanillagift.incomm.com/store/
    I tried clicking on the link: page not found


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •