Ankit Mishra
Ankit Mishra

Reputation: 41

how to open new page in same tab on clicking any option of drop down menu in html

I have a drop down list. I have links in each option, when user changes option I want to open new page in same tab. but here page opens in new tab.

<html>
   <body>
      <form name="opennew">
         <select name="sites" id="sites">
            <option value="" selected>Select Site</option>
            <option value="http://www.yahoo.com">Yahoo!!!</option>
            <option value="http://www.gmail.com">Gmail</option>
            <option value="http://www.google.co.in">Google</option>
            <option value="http://www.facebook.com">Facebook</option>
         </select>

         <input type="button" name="Submit" value="Go!" onClick="window.open(sites.value)">
      </form>
   </body>
</html>

LIVE DEMO

Upvotes: 1

Views: 7421

Answers (1)

Vukašin Manojlović
Vukašin Manojlović

Reputation: 2733

Add _parent in onClick like this:

onClick="window.open(sites.value, '_parent')"

The chosen site would be opened in parent frame which is the same window/tab.

LIVE DEMO

Upvotes: 1

Related Questions