I have a form which checks the user input is a valid UK post code, if ithe postcode isn't valid a Javascript pop-up appears. However, the post code is optional so if the input box is blank I would like like to bypass the validation.
function testPostCode () {
var myPostCode = document.getElementById('postcode').value;
if (checkPostCode (myPostCode)) {
document.getElementById('postcode').value = checkPostCode (myPostCode)
return flase;
}
else {alert ("Postcode has invalid format")};
}
"checkPostCode" is the function that performs the actual validation on the post code, I don't think it's necessary to list it here as it is very large and I'd like to bypass it anyway if the field is blank.
Thanks
Last edited by bldstr; 01-24-2006 at 03:44 AM.
Reason: Title change
I wonder if you could help me with the other thing I'm not sure of? This form goes to another page when the user clicks submit, how do I stop it forwarding if there are any validation errors?
Thanks for your response; however, I don't really understand JavaScript well enough to incorporate that into my existing script. I've been trying to work this out for the past few days, reading various forms and examples but I really don't get it.
The bits I can't figure out is what the (f) and (this) should be in correspondence with my exiting script.
I will Paypal £5 to anyone who can take this document and have the postcode validation fully work. At the moment it detects a wrongly entered postcode but does not stop the document passing to the next page if there's an error, I'm sure it would be pretty simple for anyone here to fix.
I know it's not a lot of money but it shouldn't be a big job and I can't afford any more really.
If they could also help with date validation that would be great, just PM me...
you are calling a function inside this one: checkPostCode (myPostCode)
make sure one isn't coming from there.
also by calling:
document.getElementById('sitePostcode').value = checkPostCode (myPostCode)
after the if statement, you are actually calling the same function twice
Bookmarks