Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I dont have any error and I dont know where my mistake is, could somebody please help me to solve this problem?

JavaScript
$(document).ready(function () {
           $('#Ddl').change(function () {
            var Text;
            var Value;
               Text = $(this).find(":selected").val();
               Value = $(this).val();
              alert("Text is"+Text +" and value is "+Value +");
 
           });
       });
Posted
Comments
Kornfeld Eliyahu Peter 18-Mar-15 6:05am    
What element Ddl is?
gowthami R 18-Mar-15 6:07am    
Dropdownlist
Kornfeld Eliyahu Peter 18-Mar-15 6:09am    
DropDownList is a server side control, but you are try to access it on the client...Look into your rendered page on the client. You will not find nothing like DropDownList, but some HTML elements...
Thanks7872 18-Mar-15 6:27am    
See this : http://stackoverflow.com/a/13721661/2645738

use ,
JavaScript
var text=$('#Ddl :selected').text();
              var value=$('#Ddl').val();



Check this Demo:

http://jsfiddle.net/King_Fisher/k0bqkcsb/[^]
 
Share this answer
 
v2
Try this:
C#
$(document).ready(function () {
    $('#Ddl').change(function () {
        var $this=$(this).find(":selected");
        var text=$this.text();
        var value=$this.val();
        // do something
    });
});

However, if it is an Asp.Net web form, you need to change the
Dbl 

to
<%= Dbl.ClientID %>

due to the dynamic handling of client id by the .net framework.
 
Share this answer
 
v2
Everything seems alright to me. I suspect the ID, could you try this

JavaScript
$('#<%= UrDropDownControl.ClientID %>').change(function () {

instead of this line
JavaScript
$('#Ddl').change(function () {

or
Change the line from
JavaScript
Text = $(this).find(":selected").val();

to
JavaScript
Text = $(this).find(":selected").text();


Reference: Dropdownlist index selected changed using jquery
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900