jason
jason

Reputation: 879

open a url on change of dropdown

"I need to navigate to a url on change of dropdown such that it would have done in by clicking on a link as <a href="www.abc.com" target="_blank">

My dropdown is

<select onchange="goTo(this);">
                        <option selected="selected" disabled="disabled">Back to..</option>
                        <option value="0">Manageassesment
                        </option> <option value="1">Job post
                        </option>
                    </select>

goTo function is

function goTo(ctrl){
document.location.href = (ctrl.selectedIndex) ? "www.qwe.com":"www.asd.com";

}

Now the problem is this goTo opens the url in same window but i want that it should do as it would be doing in clicking on an anchor with target="_blank"

Upvotes: 0

Views: 1313

Answers (3)

Ruud
Ruud

Reputation: 61

You can use it like this:

window.open(url, '_blank');

Upvotes: 0

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

You have to use window.open() like this:

function goTo(ctrl){
  window.open((ctrl.selectedIndex) ? "www.qwe.com":"www.asd.com");
}

Upvotes: 0

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46728

Use window.open() function to pass a target as well.

function goTo(ctrl){
window.open((ctrl.selectedIndex) ? "www.qwe.com":"www.asd.com", "_blank");
}

Upvotes: 2

Related Questions