Window.open not working for me

Window.open not working for me
0

#1

I am trying to render a new webpage per value of the input type number but I have not gotten it.

HTML

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body> 
<input type="number" id="year" placeholder="2018" step="1" min="2014" max="2018" />
	<input type="submit" id="start" value="Start" />
<script src="scripts.js"></script>
</body>

JAVASCRIPT/JQUERY

 $("#start").click(function(){
      if($("#year").val()===2018) {
        window.open("https://www.freecodecamp.org/", "_blank");
      }if($("#year").val()===2017) {
        window.open("url-2", "_blank");
      }
  }); 

I used a valid url but to no avail. The page did not render. Please how do I make it work. Thanks.


#2

Remember, that $(“year”).val() will return a string value and you are using === to compare to a number, so they will never be equal.

Also, keep in mind that a placeholder value is not the same as a user entering/selecting an actual value for the input field. If you want to make the default value 2018, then use the value attribute like value=“2018”.


#3

Wow!
Your corrections worked like a charm. It is working now. Thank a lot.