Home >Web Front-end >JS Tutorial >How Can I Persist Form Submission State Across Page Reloads?
Problem:
You need to capture the form submission event and if the form is submitted, retain this information after the page reloads, allowing you to access it when the page is reloaded.
Incorrect Approach Using Global Variables:
<br>var clicked = false;</p> <p>$(document).ready(function() {<br> $("inputtype='submit'").attr("onclick", "form.act.value='detailSearch'; clicked = true; return true;");</p> <p>if (clicked == true) {</p> <pre class="brush:php;toolbar:false">// show hidden fields
} else {
// don't show hidden fields
}
});
This code attempts to store the form submission state in a global variable, but it's ineffective because HTTP is stateless and every page reload resets all variables.
Query String:
Web Storage:
Cookies:
window.name:
The above is the detailed content of How Can I Persist Form Submission State Across Page Reloads?. For more information, please follow other related articles on the PHP Chinese website!