sunziun Posted June 28, 2012 Share Posted June 28, 2012 Hello very one, I've this peace of code which I cannot make it work. please some one help me with this <script type="text/javascript"> function disDropDown(){if(document.getElementById("one").value === "yes"){document.getElementById("two").disable='true'} else{document.getElementById("two").disable='false'}}</script> <form><select id="one"><option value="yes">Yes</option><option value="no">No</option></select> <select id="two"><option value="1">1</option><option value="2">2</option></select></form> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2012 Share Posted June 28, 2012 Where are you calling that function? With select elements you typically use the selectedIndex property and the options property to get the value, instead of the value property. And I believe the property to disable something is called "disabled". http://www.w3schools.com/jsref/dom_obj_select.asp Link to comment Share on other sites More sharing options...
sunziun Posted June 28, 2012 Author Share Posted June 28, 2012 (edited) I would like disable the whole drop down called "one" by using onChange() <select id="one" onChange="disDropDown()"><option value="yes">Yes</option><option value="no">No</option></select> I would like to use the value, not value property! Edited June 28, 2012 by sunziun Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2012 Share Posted June 28, 2012 The select element has a property called options which is an array of the options they can select, and it has a property called selectedIndex which is the index of the selected option in the options array. That option has a value property that you can use to get the value of the selected option. Link to comment Share on other sites More sharing options...
sunziun Posted June 28, 2012 Author Share Posted June 28, 2012 I am sorry but I don't get you. can you give examples? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2012 Share Posted June 28, 2012 select.options[select.selectedIndex].value Link to comment Share on other sites More sharing options...
sunziun Posted June 30, 2012 Author Share Posted June 30, 2012 Sorry but I don't how to use this. please give me comprehensible example. thanks anyways. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 2, 2012 Share Posted July 2, 2012 http://www.google.com/search?client=opera&rls=en&q=javascript+select+element+get+selected+value&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest 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