I am trying to check if a variable exists before allowing the form to submit.
Currently, the user enters the address into the form and autocomplete adds lat and long to the form. I wrote the following js
function check() {
    let latitude = document.getElementById("latitude").value;
    if (latitude == null) {
        window.prompt("ned a correct address", "");
        return false;
    } else {
        alert('It worked');
        return true;
    }
}
When I submit an address that doesn't have the lat and long autocompleted I am still getting "it worked"
Here is my form
<form method="GET" action="/search" onsubmit="check()">
    <input class="form-control" id="getaddy" type="text" placeholder="Search..." name="term" onFocus="geo()">
    <input id="latitude" type="hidden" name="latitude">
    <input id="longitude" type="hidden" name="longitude">
</form>
 
     
     
    