1

For example:

<select>
  <option value=''>Select...</option>
  <option value='http://www.google.com'>Google</option>
  <option value='http://www.yahoo.com'>Yahoo</option>
</select>

I want to redirect the selected site in a new window, such as link's attributes:

target='_blank'

I have found:

<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">

But it can only redirect to the site on current page.

pnuts
  • 58,317
  • 11
  • 87
  • 139
s-cho-m
  • 967
  • 2
  • 13
  • 28
  • s-cho-m Question already existed on the stack overflow [Your Answer][1] [1]: http://stackoverflow.com/questions/7562095/redirect-on-select-option-in-select-box – CodeLove Sep 16 '15 at 07:31
  • Yes, I found that question, but not helped me. – s-cho-m Sep 16 '15 at 07:45

2 Answers2

1

Try the FIDDLE,

updated the markup as

<select onchange="openInNewTab(this);">
  <option value=''>Select...</option>
  <option value='http://www.google.com'>Google</option>
  <option value='http://www.yahoo.com'>Yahoo</option>
</select>

Javascript

function openInNewTab(obj)
{
    //alert(obj.value);
    var win = window.open(obj.value, '_blank');
    win.focus();
}

Hope this helps...

Mayank
  • 1,351
  • 5
  • 23
  • 42
1

You can try this as well :

<select onchange="(this.options[this.selectedIndex].value?  window.open(this.options[this.selectedIndex].value,'_blank'):'')">
<option value='' >Select...</option>
<option value='http://www.google.com'>Google</option>
<option value='http://www.yahoo.com'>Yahoo</option>

Amit.S
  • 431
  • 2
  • 9