Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input onclick new tab

Tags:

html

onclick

<form name="test">
<select name="choose" style="width:300px;">
<option selected="">Select option</option>
<option value="http://url.com">Test</option>
</select>
<input onclick="location=document.test.choose.options[document.test.choose.selectedIndex].value;" value="Take me there!" type="button"></p>
</form>

Im using the following to make a dropdown list and was just wondering how i would make selected open in a new tab and not in its own window

Works fine as it is just need it to open in a new tab.

* Edit *

This worked as needed thanks

<input onClick="window.open(document.test.choose.options[document.test.choose.selectedIndex].value);" value="Take me there!" type="button">
like image 688
Dan Howes Avatar asked May 28 '13 07:05

Dan Howes


People also ask

How do I link a button to a new page?

To create a button link to another page in HTML,just add <a> tag and wrap it around the simple Html button. Inside a <a> tag simply use href=“” attribute to give the path of the desired page.

How do you open a link that clicks a button?

Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location. Using button tag inside <a> tag: This method create a button inside anchor tag.


3 Answers

try window.open

window.open('http://www.google.com');

update

live demo - http://jsfiddle.net/im4aLL/tzp4H/

like image 172
HADI Avatar answered Nov 09 '22 00:11

HADI


function open_in_new_tab(url )
{
  var win=window.open(url, '_blank');
  win.focus();
}

Call that function when you want to open a link in a new tab. Also check here and here

like image 42
imulsion Avatar answered Nov 09 '22 00:11

imulsion


Regarding your updated answer to your original post:

Adding ,'_blank' after the .value like so:

<input type="button" onClick="window.open(document.test.choose.options[document.test.choose.selectedIndex].value,'_blank');>

Actually opens in a new tab instead of an entirely new browser window.

like image 26
gyrofly Avatar answered Nov 08 '22 23:11

gyrofly