Jump to content

Drop Down Dependencies


sunziun

Recommended Posts

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

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

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 by sunziun
Link to comment
Share on other sites

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

Sorry but I don't how to use this. please give me comprehensible example. thanks anyways.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...