Reputation: 3
this is the code I am using, I have specified target="_blank" in the form however it doesn't open in a new tab.
<script>
function process()
{
var url="https://website.com/search/" + document.getElementById("url").value;
location.href=url;
return false;
}
</script>
<form action="https://website.com/search/" target="_blank" onSubmit="return process();">
Search: <input type="text" name="url" id="url"> <input type="submit" value="go">
</form>
Upvotes: 0
Views: 68
Reputation: 781974
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;
with:
window.open(url, "_blank");
Upvotes: 1