Advertisement

09.04.2006 at 08:09AM PDT, ID: 21977473
[x]
Attachment Details

Getting SelectedValue from DropDownList in Javascript.

Asked by tfewster500 in JavaScript

Tags: javascript, dropdownlist, selectedvalue

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:Controls();"

<script language="javascript">
       function Controls() {
              alert( document.form1.cboType[document.form.cboType.selectedIndex].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:Controls(this);"

<script language="javascript">
       function Controls(obj) {
              alert( obj[obj.selectedIndex].value );
       }
<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
[+][-]09.04.2006 at 08:11AM PDT, ID: 17450116

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 08:11AM PDT, ID: 17450117

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 08:13AM PDT, ID: 17450127

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 08:15AM PDT, ID: 17450141

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 08:16AM PDT, ID: 17450147

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 08:16AM PDT, ID: 17450149

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 08:18AM PDT, ID: 17450159

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2006 at 07:40PM PDT, ID: 17453013

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.07.2006 at 12:39PM PDT, ID: 17474010

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.11.2006 at 08:08AM PDT, ID: 17495151

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: javascript, dropdownlist, selectedvalue
Sign Up Now!
Solution Provided By: ee_ai_construct
Participating Experts: 6
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32