ex501 ex501 - 1 year ago 59
Javascript Question

Redirect based on user input

I have 20 different pages. Let's say that IDs of the pages are for example:

mysite.com/page1
,
mysite.com/page2
and so on...

I need to create an input field where the user can enter numbers, and if he inputs number 16 for example, it will redirect him to
mysite.com/page16
.

I believe that this is possible with JavaScript. Has anyone got any advice?

Answer Source

window.onload = function() {
  document.getElementById('btn').onclick = function()
  {
    window.location.href = "http://www.yourdomain.com/page"+document.getElementById("url").value
  };
}
<input id="url" value="">
<button id="btn">Go!</button>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download