Chikwado Posted January 6, 2015 Share Posted January 6, 2015 (edited) How to make hyper link in option, I have try html code all the way but not successfull. The code are: <html> <body><script> function change() { if(document.getElementById("option1").selected==true) {window.open('http://www.google.com/' , 'target')};} </script><select onchange= "changelink()"><option id="option1">My Link</option></select></body></html> Then when I click the link it do not open google, Some one help. Edited January 27, 2015 by Chikwado Link to comment Share on other sites More sharing options...
justsomeguy Posted January 6, 2015 Share Posted January 6, 2015 Option elements do have not a property called selected. The select element has a property called selectedIndex, though, and an array of options. 1 Link to comment Share on other sites More sharing options...
Chikwado Posted January 6, 2015 Author Share Posted January 6, 2015 You mean that I have to use "selectedIndex" instead of selected? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 6, 2015 Share Posted January 6, 2015 You can use the selectedIndex property of the select element, not the option element, and the select element's options array to get the selected option. Look up how to get the selected option of a select element and you'll find examples. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now