Webpage redirect to submitted text value

  html, javascript, redirect

I want to create a static webpage which has a text field and a submit button, which after a user submits text it would automatically redirect from localhost/ to localhost/<test_person_submitted> .

Up to this point, this JavaScript is the only thing I was able to clobber together from all of the guides I found

function confirmInput() {
  fname = document.forms[0].fname.value;
  url = "http://localhost/"
  command = (url + fname)
  location.replace(command);
}

That does work, but no matter what I added as HTML to invoke the function it doesn’t work properly.

Can someone please add a submit form that will properly execute this?
Right now I’m stumped and I just want to consider this small project "complete", rather to just leaving it without ever knowing how it could be resolved.

If you are wondering why I want to do this it’s because I’m going to try to invoke some wild-card commands that will return JSON.
And this is just a fun project for me.

Source: Ask Javascript Questions

LEAVE A COMMENT