JStoffell JStoffell - 10 months ago 42
HTML Question

Form does not open in new tab

this is the code I am using, I have specified target="_blank" in the form however it doesn't open in a new tab.

function process()
var url="https://website.com/search/" + document.getElementById("url").value;
return false;
<form action="https://website.com/search/" target="_blank" onSubmit="return process();">
Search: <input type="text" name="url" id="url"> <input type="submit" value="go">


The target is only used when the form is submitted normmally. You're preventing this by returning false from the onsubmit function.

Since process is redirecting to a new URL instead of submitting the form, you can instead open a new window/tabl there. So replace

locaiton.href = url;


window.open(url, "_blank");