Add form input to URL in a new tab

34 Views Asked by At

I'm currently using the below to add a user's input to a URL but it opens in the same window. I've tried window.open to get the link to open in a new tab with no luck. I've also tried adding _blank but it appends that to the URL.

<form onsubmit="window.location = 'https://demosite.com/' + input1.value; return false;">
<input id="input1" placeholder="Placeholder" name="input1"/>
<input type="submit" value="Send"/>
</form>
1

There are 1 best solutions below

0
Indika Pradeep On

You can use window.open fucntion with target as '_blank'.

try this code

enter code here
<form onsubmit="window.open ('https://demosite.com/' ,'_blank'); return false;">
<input id="input1" placeholder="Placeholder" name="input1"/>
<input type="submit" value="Send"/>
</form>

more further you can refer this link https://developer.mozilla.org/en-US/docs/Web/API/Window/open

Thanks