Mochiron Desu
Mochiron Desu

Reputation: 17

How to open a new tab when I select a option in Select Tag?

I want to open a new tab when I select any of the options in the select box how to implement it ?

Html code:

<body>
    <h1>Select the country you want to know about</h1>
    <br>
    <form>
        <select name="Countries and its Name" onchange="location = this.value;">
            <option selected>---Select---</option>
            <option value="india.html">India</option>
            <option value="usa.html">United States of America</option>
        </select>
    </form>
</body>

I am only able to open it in the same tab, but how to open in a new tab?

Upvotes: 0

Views: 2621

Answers (1)

T J
T J

Reputation: 43156

You can open a new tab programmatically usingwindow.open() method by passing _blank as window name.

<h1>Select the country you want to know about</h1>
<br>
<form>
  <select name="Countries and its Name" onchange="window.open(this.value, '_blank')">
    <option selected>---Select---</option>
    <option value="india.html">India</option>
    <option value="usa.html">United States of America</option>
  </select>
</form>

Upvotes: 2

Related Questions