Shane Hicks Shane Hicks - 1 year ago 62
HTML Question

Redirect to Page based on Input Value

I am attempting to create a form on the page that requires the user to input text. Once the form is submitted, the user will then be redirected to the page assigned to it. My question is where am I going wrong and how should I resolve this issue? Could someone include a JSFiddle or pen for deminstration purposes?

For example:

  1. User enters and submits "123456"

  2. User is then redirected to the page

I am assuming it is something like this:


<input id="projectid" maxlength="6">
<input onclick="findProject()" type="submit" value="Go">


function findProject(){
document.location = document.getElementById('projectId').value();

I have included my own pen:

Answer Source

Put a / before the url fragment

document.location = '/' + document.getElementById('projectId').value;

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