I'm trying to get the SelectedValue from a DropDownList (WebControl) so I can enable / disable other controls based on the values the user has selected. My form is called Form1 and my dropdownlist control is cboType.
Here is my code...
With the definition of the dropdownlist I have onChange="javascript:Contr
ols();"
<script language="javascript">
function Controls() {
alert( document.form1.cboType[doc
ument.form
.cboType.s
electedInd
ex].value );
}
<script>
THIS CODE DOES NOT WORK. THE ERROR IS THAT THE OBJECT IS NOT DEFINED.
If I change the code so that the object is passed into the javascript function, everything works fine. Here is the code.
With the definition of the dropdownlist I have onChange="javascript:Contr
ols(this);
"
<script language="javascript">
function Controls(obj) {
alert( obj[obj.selectedIndex].val
ue );
}
<script>
Something must be wrong in my first set of code with respect to how I refer to the dropdownlist (document.Form1.cboType). What have I done wrong in the first example?
Start Free Trial