0

I'm trying to write an if statement code to redirect users below 18 to a separate website from users above and equal to 18 but the code isn't running, can someone figure out and explain what the problem is?

<body>
<div>
    <form>
        How old are you?
        <br>
        <br>
        <input type="text" id="number">
        <button onclick = submit();>Submit</button>
    </form>
</div>
<script>
   

   function submit() {
        var number= document.getElementById("number");

        if (number >= 18 ) {
            location.href = "inec.com.ng"
        ;}
        else if (number== isNaN){
            alert('Input a number');
        }
        else {location.href = "www.google.com";}
    }
</script>

1 Answers1

0

You're trying yo use the DOM element itself instead of using its value . Once you get its value, don't forget to cast is to an int with parseInt:

var number = parseInt(document.getElementById("number").value);
Koby Douek
  • 16,156
  • 19
  • 74
  • 103