Home > Software design >  Create Input box with Submit Button Redirect to site
Create Input box with Submit Button Redirect to site

Time:11-08

I want help in creating a Input box with only a submit button which redirect user to another site.

when user typed a url in the input box and clicked submit button

CodePudding user response:

document.getElementById("myBtn").addEventListener("click", myFunction); function myFunction() { window.location.href="http://programminghead.com"; }

CodePudding user response:

First make an input box and a Button in HTML

<input type="text" id="link"><br/>
<button onclick="redirectFunction()">Redirect me!</button>

Then in your javascript file

function redirectFunction(){
    const link = document.getElementById("link").value;
    window.location.href = link;
}

Remember to put the <script> tag into the body of the html file

  • Related