javascript - How can I have a function cause all but the first option in a drop down menu open a new webpage? -


this code have far:

`<!doctype html> <html> <head> </head> <body>  <img src="http://blog.dubspot.com/files/2011/09/dubspot-dj-producer-banner-2.jpg" alt="electronicmusic" width="1350" height="250">  <h1>electronic music sampler</h1><br>  <p>select genre sample</p>  <form>  <select id="select" onchange="window.open(this.options[this.selectedindex].value,'_parent')">   <option value="genre">select genre</option>   <option value="https://www.youtube.com/watch?v=swxjxt1hjrs">ambient</option>   <option value="https://www.youtube.com/watch?v=jrftxciqfq8">breakbeat</option>    <option value="https://www.youtube.com/watch?v=rgoz_cpem8a">chiptune</option>   <option value="https://www.youtube.com/watch?v=6gmgjvac-ws">downtempo</option>   <option value="https://www.youtube.com/watch?v=dd40vxfkusw">drum , bass</option>   <option value="https://www.youtube.com/watch?v=5nv6rdv1a3i">electro house</option>   <option value="https://www.youtube.com/watch?v=6gqrsmffevi">electronica</option>   <option value="https://www.youtube.com/watch?v=amimeo279ye">electronic rock</option>   <option value="https://www.youtube.com/watch?v=84tyi3fomlu">house</option>   <option value="https://www.youtube.com/watch?v=voc35uvlq7u">industrial</option>   <option value="https://www.youtube.com/watch?v=lhuqygjp7pq">progressive electronic</option>   <option value="https://www.youtube.com/watch?v=wqnglhoynck">techno</option>   <option value="https://www.youtube.com/watch?v=atftgqof-cu">trance</option>   <option value="https://www.youtube.com/watch?v=fmdxoqq3wl4">dubstep</option>   <option value="https://www.youtube.com/watch?v=xvlakrvbcbm">idm</option>   <option value="https://www.youtube.com/watch?v=fiea0zmpxik">glitch</option> </select>  </form><br>  <p>select artist discography</p>  <form> <select id="discographies" name="select" onchange="window.open(this.options[this.selectedindex].value,'_parent');">   <option value="discography">select artist</option>   <option value="https://en.wikipedia.org/wiki/richard_d._james_discography">aphex twin</option>   <option value="https://en.wikipedia.org/wiki/bassnectar#discography">bassnectar</option>   <option value="https://en.wikipedia.org/wiki/nullsleep#discography">nullsleep</option>   <option value="https://en.wikipedia.org/wiki/zero_7_discography">zero 7</option>   <option value="https://en.wikipedia.org/wiki/rusko_(musician)#discography.5b8.5d">rusko</option>   <option value="https://en.wikipedia.org/wiki/daft_punk_discography">daft punk</option>   <option value="https://en.wikipedia.org/wiki/the_chemical_brothers_discography">the chemical brothers</option>   <option value="https://en.wikipedia.org/wiki/celldweller_discography">celldweller</option>   <option value="https://en.wikipedia.org/wiki/deadmau5_discography">deadmau5</option>   <option value="https://en.wikipedia.org/wiki/nine_inch_nails_discography">nine inch nails</option>   <option value="https://en.wikipedia.org/wiki/feed_me#discography">feed me</option>   <option value="https://en.wikipedia.org/wiki/fatboy_slim_discography">fatboy slim</option>   <option value="https://en.wikipedia.org/wiki/kaskade#discography">kaskade</option>   <option value="https://en.wikipedia.org/wiki/skrillex_discography">skrillex</option>   <option value="https://en.wikipedia.org/wiki/squarepusher#discography">squarepusher</option>   <option value="https://en.wikipedia.org/wiki/koan_sound">koan sound</option> </select> </form><br>  <p>did find webpage helpful?</p>  <form action="http://www.hirebilinguals.com/wp-content/uploads/2013/02/thank-you-400x304.jpg" method="get"> <input type="radio" name="answer" value="yes">yes<br> <input type="radio" name="answer" value="no">no<br> <input type="submit" name="submit" value="submit"> </form>  </body> </html>` 

this intro computer science class, , last step of project need finish. when first option in dropdown selected, tries go different url, because have not identified url go to, opens "webpage not found" page. need first option in drop down not anything, other options open pages have specified.

change

window.open(this.options[this.selectedindex].value,'_parent') 

to

if (this.selectedindex > 0) window.open(this.options[this.selectedindex].value,'_parent') 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -