I want to Retain the textbox values even after Refresh of page rather it is successfully submitted.
Using cookies or using php sessions
Here is the code Below :
<script>
$("#target").change(function(){
if($(this).is(":checked")) {
if (localStorage['first-name']) {
$("input[name='first-name']").val(localStorage['first-name']);
}
if (localStorage['last-name']) {
$("input[name='last-name']").val(localStorage['last-name']);
}
if (localStorage['your-email']) {
$("input[name='your-email']").val(localStorage['your-email']);
}
}
});
$(".wpcf7-text").on("change",function () {
//store vlues in session
localStorage.setItem($(this).attr("name") , $(this).val());
});
</script>
Oh yea!! You can use localStorage
or sessionStorage
of HTML5.
sessionStorage
will keep it until a session is alive but
localStorage
will keep it until you delete it manually.
See below for ways you can store it in either of them:
To Store:
localStorage.setItem('somekey','textboxValue')
//or
sessionStorage.setItem('somekey','textboxvalue')
To Retrieve
localStorage.getItem('somekey')
//or
sessionStorage.getItem('somekey');
You could solve this using jQuery and local storage.
This has been answered here: Saving form data to local storage and show it on refresh
It basically runs a load/save command when the page changes.