dimanche 12 juin 2016

stop submitting a form with jquery

hello I am trying to stop the submiting process with jquery but it doesnt work...

Here is the curent code the submition process should be stopped wehre return false is.

function validateinput(gu) {

var geocoder= new google.maps.Geocoder();
var address = $(gu).find("input[name=autocomplete]").val();


geocoder.geocode( { 'address': address, 
  componentRestrictions: {
      country: 'DE'
    }}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {

      if(!results[1]){


          $.each(results[0].address_components, function(){

          if(this.types[0] == "street_number"){ street_number = this.long_name; }
          if(this.types[0] == "route"){ route = this.long_name; }
          if(this.types[0] == "administrative_area_level_1"){ administrative_area_level_1 = this.long_name; }
          if(this.types[0] == "postal_code"){ postal_code = this.long_name; }

          });


    if(typeof(street_number) !== "undefined" && street_number !== null && street_number !== '') {
      $(gu).find("input[name=street_number]").val(street_number);
      $(gu).find("input[name=route]").val(route);
      $(gu).find("input[name=administrative_area_level_1]").val(administrative_area_level_1);
      $(gu).find("input[name=postal_code]").val(postal_code);
      $(gu).find("input[name=lat]").val(results[0].geometry.location.lat());
      $(gu).find("input[name=lng]").val(results[0].geometry.location.lng());
return true;
    }else{

      $(gu).find("input[name=autocomplete]").val(administrative_area_level_1 + ", " + route + " ");
      $(gu).find("input[name=autocomplete]").focus();
      $(gu).find('span.addr_error').html('Bitte gebe deine Hausnr. an.');
return false;

    }


      }else{

      $(gu).find("input[name=autocomplete]").focus();
      $(gu).find('span.addr_error').html('Bitte wähle deine Lieferadresse.');
return false;



      }



    }else {
      $(gu).find("input[name=autocomplete]").focus();
      $(gu).find('span.addr_error').html('Wir konnten deine Adresse nicht finden.');
return false;

  });

}


$("#aadress-form").submit(function(){ return validateinput(this) });
$("#ladress-form").submit(function(){ return validateinput(this) });

How do I stop the form submitting? Sry for my bad english I hope you understand my problem and can help me.

Aucun commentaire:

Enregistrer un commentaire