i m using a select box of country, when user select a country then add branch link appears and user add branches under that country, but when user want to change country then al
You can just store the previous value and set it back if needed, like this:
var countryVal;
$("#country").change(function() {
var newVal = $(this).val();
if (!confirm("Are you sure you wish to destroy these country branches?")) {
$(this).val(countryVal); //set back
return; //abort!
}
//destroy branches
countryVal = newVal; //store new value for next time
});
Or use .data()
as @Gaby suggests, like this:
$("#country").change(function() {
var newVal = $(this).val();
if (!confirm("Are you sure you wish to destroy these country branches?")) {
$(this).val($.data(this, 'val')); //set back
return; //abort!
}
//destroy branches
$.data(this, 'val', newVal); //store new value for next time
});