Defining functions and if statement problems
- by David Fairbairn
I'm having a problem with two functions and an if statement. I'm being told the functions go and postcodeChange are not defined.
I'm also being told flag is an unexpected identifier at if flag == 1.
Any idea where I am going wrong? Thank you.
function postcodeChange(){
document.getElementById("goButton").onclick = distanceCheck;
}
function distanceCheck(){
var distance = document.getElementById("distance").value
var patt1=new RegExp("^[0-9]+(\.[0-9]{1})?$");
var out = patt1.exec(distance);
if (out == null) {
//distance is not a valid number
document.getElementById("distanceFlag").value = 1
}
else {
//distance is valid number
document.getElementById("distanceFlag").value = 0
}
function go(){
var flag = document.getElementById("distanceFlag").value
if flag == 1
{
alert("Distance is not valid- enter a number with no more than one decimal point");
}
else{
popSubmit('#fa Care Provider Search Go','','0');
}
}