Defining functions and if statement problems

Posted by David Fairbairn on Stack Overflow See other posts from Stack Overflow or by David Fairbairn
Published on 2013-06-25T10:14:31Z Indexed on 2013/06/25 10:21 UTC
Read the original article Hit count: 315

Filed under:

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');
}
}

© Stack Overflow or respective owner

Related posts about JavaScript