Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
$(document).ready(function () {
        $("#ddlPA").change(function () {

            var url = "Reports/Models";
            var ddlsource = "#ddlPA";
            var ddltarget = "#ddlPSA";
            var selectedPSA = $(this).val();
            
            $.getJSON('@Url.Action("Models")', { param: $(ddlsource).val(), id: selectedPSA },
                 function (data) {
                     $(ddltarget).empty();
                     $.each(data, function (index, optionData) {
                         $(ddltarget).append("<option value='" + optionData.Text + "'>" + optionData.Value + "</option>");
                     });

                 });

                 if (selectedPSA = null || selectedPSA == '') {
                     $(ddltarget).hide();
                 }
                 else
                 {
                     $(ddltarget).show();

                 }

        });

    });

So,here is my dropdownlist id = ddlPA, when a user select a value in dropdownlist , i want to get that selected index to perform further actions , how can i obtain it?
Posted
Updated 21-Sep-12 0:44am
v2
Comments
drstylo 21-Sep-12 7:15am    
$("#ddlPA").get(0).selectedIndex

I found this online. This got me the selected index but i am not able to set it.
Example : $("#ddlPA").get(0).selectedIndex = 2 is not working. Please help in it.

1 solution

There are many ways you can try withe followings....
1) $("#ddlPA option:selected").text();
2) $('#ddlPA').find('option:selected').text();
3) $("#ddlPA :selected").text();
 
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