0

i have numbers of dropdownlist, so i want to change event of every dropdownlist in form, when i select particular dropdownlist item then it will fire event for particular dropdownlist only... here is two sample of dropdownlist

 <asp:DropDownList ID="ddlGender" runat="server" AutoPostBack="True">

     <asp:DropDownList ID="ddlMaritalStatus" runat="server" AutoPostBack="True">

Please help me as soon as possible Thank you

I tried this

 $(document).ready(function () {
    $('input:text').each(function () {
        $(this).attr('disabled', true);
    });
    $("select").change(function () {
        alert(this.value);
        if (this.value != "User Select") {
            alert(this.value);
            $('input:text').each(function () {
                $(this).attr('disabled', false);
            });

        }
        if (this.value == "User Select") {
            $('input:text').each(function () {
                $(this).attr('disabled', true);
            });
        }
    })
});

here last condition is not working, please help

2
  • @user..your question is not at all clear.. explain more. Commented Mar 19, 2014 at 10:00
  • What have you tried? What isn't working? And what does this have to do with jQuery? (Hint: These are set to AutoPostBack="True" which is going to reload the whole page, rendering any JavaScript event handlers moot.) Commented Mar 19, 2014 at 10:01

3 Answers 3

1

You can assign a common class to all dropdownlist and use class selector to bind the change event using jQuery

HTML

<asp:DropDownList ID="ddlGender" class="ddl" runat="server" AutoPostBack="True">
<asp:DropDownList ID="ddlMaritalStatus" class="ddl" runat="server" AutoPostBack="True">

Javascript  

$('.ddl').change(function(){
     alert(this.id);
 });

If you do not want to use class selector, you will need to bind event with id selector

$('#<%= ddlGender.ClientID %>, #<%= ddlMaritalStatus.ClientID %>').change(function(){
     alert(this.id);
});
Sign up to request clarification or add additional context in comments.

Comments

0

You can write a javascript function and invoke it on onchange event of dropdownlist...

    DropDownList ID="ddlGender" class="ddl" runat="server" AutoPostBack="True" onchange="Check()">
    <asp:DropDownList ID="ddlMaritalStatus" class="ddl" runat="server" AutoPostBack="True" onchange="Check()">

    function Check()
    {
       alert('Hii');
    }

Comments

0

Use SelectedIndexChanged event.

<asp:DropDownList ID="ddlGender" runat="server" AutoPostBack="True" OnSelectedIndexChanged="EventHandler1">
     <asp:DropDownList ID="ddlMaritalStatus" runat="server" AutoPostBack="True" OnSelectedIndexChanged="EventHandler2">

In code-behind add below functions for each dropdownlist

void EventHandler1(Object sender, EventArgs e) 
{
   // code for event handler1
}


void EventHandler2(Object sender, EventArgs e) 
{
   // code for event handler1
}

For more details check example given in below link

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged(v=vs.110).aspx

1 Comment

Thanx brother, but i would like it with jquery or javascript... Thanx :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.