Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
JavaScript
<script type="text/javascript" >
            $(document).ready(function(e) {

                $("#State").change(function (e) {

                    var selectedValue = $(this).val();
                    if(selectedValue != "Select") {
                        $.ajax({
                            url: '@Url.Action("GetCities","Employer")',
                            type: 'Post',
                            //data:  { "selectedValue": selectedValue},
                            data: {id: $("#State").val()},
                            dataType: 'json',
                            success: function(response) {
                                var items = "";
                                $.each(response, function(i, city) {
                                    $("#City").append('<option value="' + city.Value + '">' + city.Text + '</option>');
                                });
                            },
                            error: function (ex)
                            {
                                alert("Failed To Receive States" + ex);
                            }
                        });  
                    }
                }) 
            })

        </script>
Posted
Comments
prateek4506 20-Jun-14 8:11am    
I wan to display the list of cities according to the state selected. But I'm not able to call this script.
SRS(The Coder) 20-Jun-14 8:53am    
Is it throwing error nothing is happening at all ?
prateek4506 20-Jun-14 9:01am    
No bro its not throwing error but its not being called either when we select the state from dropdown. This is the main issue. Please find some solution . You answer will be appreciated. If you want I can post the dropdown codes also.
SRS(The Coder) 23-Jun-14 2:10am    
You can check with your browser's developer tool to check the exact issue.

Open the page press F12 to open the developer's tool for IE/Mozilla/Chrome.
Click on the console tab in the developers tool.
Then select the States dropdown now you can see the error if any in the console window, and you can proceed to fix it.

Or else if you are still facing any problem then please post the code so that i can analyse the code to give you a proper solution.

 
Share this answer
 
I imaging that you have the value of select as 0(zero)

It is not getting called because of this below two lines

SQL
var selectedValue = $(this).val();
                  if(selectedValue != "Select") {


try this

SQL
var selectedValue = $(this).val();
                  if(selectedValue != "0") {
 
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