This is supposed to be easy, but I could not figure out how to do it. I have a textbox where a user will type a name to search for. Then, the user will have to provide some additional information such as selecting the state where the person live from a drop down. After the state is selected, I am doing an Ajax post to get a list of cities within that state. The issue is that as soon as the Cities are loaded, I lost the value that was typed in the textbox. How can I make this textbox persistent, so I don't loose the value?
function ValueSelected(state, city, zip) {
var SelectedState = state;
var SelectedCity= city;
var ZipCode= zip;
if (SelectedState.length > 0) {
// var url = '@Url.Action("SetState", "FindPerson")';
$.ajax({
url: '@Url.Action("SetState", "FindPerson")',
type: 'POST',
datatype: 'text',
data: { "SelectedState": SelectedState, "SelectedCity": SelectedCity, "ZipCode": ZipCode},
cache: false,
// contentType: 'application;text;charset=UTF-8',
success: function (e) {
window.location.href = window.location.href;
},
error: function (e) {
alert('error');
}
});
}
}
Update 08/07/2014 :
I write a function that will add the textbox value to a cookie when the user select something from the drop down. Then, I check the cookie to see if the cookie has something in it when the page is loaded. I set the cookie to expire after 30 minutes.
function setCookieInfo(name, value) {
if (name != null && name != "") {
setCookie(name, value, 24);
}
}