Search code examples
javascripthtmlurlinputtext

How to open URL that is inside of textbox


So I have tried this one: <input type="url" id="textbox" /> <input type="button" id="btn" value="Submit" onClick="javascript: window.location = document.getElementById('textbox').value; /> What I tried to do was that my site would have a text area where I can write a URL and then once you've pressed "Submit" would go to that site without opening a new window or tab. What mistake I have made?


Solution

  • <input type="url" id="textbox" /> <input type="button" id="btn" value="Submit" onClick="window.location = document.getElementById('textbox').value;" />