T
T
TheEZIC2018-03-29 14:53:22
PHP
TheEZIC, 2018-03-29 14:53:22

How to make input type="text" input value persist after page refresh?

I have a text field (for a calculator on a site), I need it to save the value after refreshing the page

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2018-03-29
@TheEZIC

Write to sessionStorage: https://developer.mozilla.org/en/docs/Web/API/Wind ... /Web/API/Wind... If there is no support in the browsers you need, then in cookies: https://developer.mozilla.org/en/docs/Web/API/Docu... Bibla for convenient work with cookies: https://www.npmjs.com/package/js-cookies

E
Eugene, 2018-03-29
@evgen9586

Cookies

<?php 
if(!empty($_POST)) {     
         SetCookie("email", $_POST['email'],time()+31536000);     
}

$email = !empty($_COOKIE['email']) ? $_COOKIE['email'] : '';

?>

<form>
    <input type="text" name="email" value="<?php echo $email; ?>" />
</form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question