mercredi 31 décembre 2014

get valve of javascript variable and pass it to modal from view to get the list


I have 3 select dropdown fields Country,State,City.Onload of the page only country field is enabled (city and state fields are disabled)then if user select country then state field is enabled(with all the states mapped on that country stored in my database) then if user select state then city field is enabled(with all the city mapped on the on that state stored in my database).My dropdowns code are



<select class="form-login" id="country_id" onchange="setDropdownState();">
<option value="select" >Select country</option>
@for(country <- countryList) {
<option value="@country.getId" >@country.getName</option>
}
</select>
<select class="form-login" id="state_id" onchange="setDropdownCity();">
<option value="select" >Select country</option>
@for(state<- Country.findStateByCountryId(get value of cid from setDropdownState function)) {
<option value="@state.getId" >@state.getName</option>
}
</select>
<select class="form-login" id="city_id" >
<option value="select" >Select country</option>
@for(city<- State.findCityByStateId(get value of sid from setDropdownCity function)) {
<option value="@state.getId" >@state.getName</option>
}
</select>


scripts



$(document).ready(function() {
$("#state_id").attr("disabled", true);
$("#city_id").attr("disabled", true);
});

function setDropdownState() {
var cid = $("#country_id").val();
if (cid != "select") {
//pass value to state dropdown
$("#state_id").attr("disabled", false);
} else {
$("#state_id").attr("disabled", true);
$("#city_id").attr("disabled", true);
}


}

function setDropdownCity() {
var sid = $("#state_id").val();
if (sid != "select") {
//pass value to citydropdown
$("#city_id").attr("disabled", false);
} else {
$("#city_id").attr("disabled", true);
}
}


So I have to pass country_id value onchange of country select box to get state field for loop value Country.findStateByCountryId(get value of cid from setDropdownState function) and in the same way pass state_id on change of state field to city field for loop to get the desired city on that particular state State.findCityByStateId(get value of sid from setDropdownCity function).


So how can I pass javascript value to model??


Is It possible??


Or is there any other way to do this??


Thanks





Aucun commentaire:

Enregistrer un commentaire