Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi to all,
here i completed Populate country automatically load state and automatically load city. but i need default value Country-India,State-delhi how to set default value.Here i used jquery.Kindly read and answer me.
Posted
Comments
Jameel VM 31-Oct-14 6:04am    
can you please post the code for loading the dropdowns
JOTHI KUMAR Member 10918227 31-Oct-14 6:05am    
hmm sure
JOTHI KUMAR Member 10918227 31-Oct-14 6:06am    
$(function () {
$('#Country').val(1);
$('#State').val(1);
$('#Country').change(function () {
debugger;

$.getJSON('/Branch/StateList/' + $('#Country').val(), function (data) {
var items = '<option>Select a State</option>';
$.each(data, function (i, state) {
items += "<option value='" + state.Value + "'>" + state.Text + "</option>";
});
$('#State').html(items);
});
});

$('#State').change(function () {
$('#City').val(1);
$.getJSON('/Branch/CityList/' + $('#State').val(), function (data) {
var items = '<option>Select a City</option>';
$.each(data, function (i, city) {
items += "<option value='" + city.Value + "'>" + city.Text + "</option>";

});
$('#City').html(items);
});
});
});
</script>

This is my loading dropdown script but i want to set Default value when Load the index and add new.
Jameel VM 31-Oct-14 6:38am    
default value means appending Country- with all countries in dropdown?

Hi,

I'm not very clear with your requirement.
I'm guessing your requirement and if u r talking abt a dropdown list try something like this.

$("#country").val("India");


use this while page is loading.later use selection change event to select other values.

Good Luck
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 31-Oct-14 6:40am    
sorry not working,where to put this code .Here i put after this line$('#Country').change(function () {
$("#country").val("India");
If its correct
try like below
XML
<script>
$(function () {
$('#Country').val(1);
$('#State').val(1);
$('#Country').change(function () {
debugger;

$.getJSON('/Branch/StateList/' + $('#Country').val(), function (data) {
var items = '<option>Select a State</option>';
$.each(data, function (i, state) {
items += "<option value='" + state.Value + "'>" + state.Text + "</option>";
});
$('#State').html(items);
//here you can set the default value for country
$('#State').val("India");
});
});

$('#State').change(function () {
$('#City').val(1);
$.getJSON('/Branch/CityList/' + $('#State').val(), function (data) {
var items = '<option>Select a City</option>';
$.each(data, function (i, city) {
items += "<option value='" + city.Value + "'>" + city.Text + "</option>";

});
$('#City').html(items);
//here you can set the default value for city
$('#City').val("delhi");

});
});
});
</script>

Hope this helps
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 31-Oct-14 6:57am    
i will try and tell you ok
JOTHI KUMAR Member 10918227 31-Oct-14 7:03am    
where to set state ???
Jameel VM 31-Oct-14 7:22am    
when you want to set the default value?
JOTHI KUMAR Member 10918227 31-Oct-14 7:35am    
here i want to set default value as Country -India,State-Andra,City-Kadapa. Here i want to set this default.When i load the Index or add new i need this but Here default country i want respective state and city.not load all state and city.
JOTHI KUMAR Member 10918227 31-Oct-14 7:38am    
here i want MVC :-
here i want to set default value as Country -India,State-Andra,City-Kadapa. then i want to set this default value load from database.When i load the Index or add new i need this but Here default country i want respective state and city.not load all state and city.

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