简体   繁体   中英

How to complete a link with user input

I'm completely new to javascript, and I'm trying to get a script to complete a link with a user input.

Ie I have a common base url like http://www.mystuff.com/ and I would like to create a form to let the user reach a specific page if he knows the exact url. I need a basic input field where he can write a string (like h5mlf4) that will send him clicking the submit button to http://www.mystuff.com/h5mlf4 .

I've found this script on this page which is pretty close to my needs. I've tried to modify it, but I don't know how to do both the actions (add the user's input and launch the link) on the same button with an all-in-one action. I don't want to create the link on the page, I simply need it to be immediately used.

I hope to have been clear, and thanks to everybody will take care of this.

Do

window.location = "http://www.google.com?q=" + userInput;

to "click" that link (ie go to that link) for the user.

Doc for window.location >> https://developer.mozilla.org/en-US/docs/DOM/window.location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM