Save form data in cookie and popular form with this data after reload of the page

0

I have a page with filters, being 4 selects, an input search, 2 input date and a submit, I need to keep the data selected after reloading the page.

In other words, I put the data to filter and after clicking the submit and the load page it needs to keep the values of the form as selected before submit.

At first I'm saving in cookie with the code below, but despite saving cookies, I wanted to know if I can decrease this code? Type instead of using a $.cookie for each input, use one for the whole form.

And also I would like to know how popular the new form with cookie data and if this can not cause me problems it getting stored, can delete cookies after using them?

$(".searchButton").on("click", function () {
	$.cookie('frachiseesValue', $("#frachisees_filter").val());
	$.cookie('schoolsValue', $("#schools_filter").val());
	$.cookie('challengeValue', $("#post_challenges_filter").val());
	$.cookie('statusValue', $("#statuses_filter").val());
	$.cookie('searchValue', $("#filter_search").val());
	$.cookie('startDateValue', $("#startDate").val());
	$.cookie('endDateValue', $("#endDate").val());
});

Update

    
asked by anonymous 27.04.2017 / 20:17

1 answer

0

To load the select, do so.

1- Load the select fields (all select items)

$(function(){
    $("#frachisees_filter").val($.cookie('frachiseesValue'));
	$("#schools_filter").val($.cookie('schoolsValue'));
});

And so on for all other selects

    
27.04.2017 / 21:11