vendredi 29 avril 2016

Javascript redirect URL

Below is a bit of script I'm using in related to a form for a site. I'm trying to get it to redirect to a specific page if the first two functions aren't valid.

What's happening is that the redirect is happening even if the functions are valid

I'm sure I'm missing something really simple here...

Any help appreciated!

(function(){
var f1 = fieldname2,
    valid_pickup_postcode = function (postcode) {
    postcode = postcode.replace(/\s/g, "");
    var regex = /^[O,X]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}$/i;
    return regex.test(postcode);
    };
var f2 = fieldname7,
    valid_dropoff_postcode = function (postcode) {
    postcode = postcode.replace(/\s/g, "");
    var regex = /^[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}$/i;
    return regex.test(postcode);
};

if( AND(f1,f2))
{
   if( valid_pickup_postcode(f1) && valid_dropoff_postcode(f2))
   {
      return 'Please select the vehicle you require for your delivery';
   }
   else
   {
      return window.location.href = "http://www.bing.com";
   }
}
else
{
return '';
}
})()

Aucun commentaire:

Enregistrer un commentaire