You can check the code below, this may help you.
<html> <head> <script> var today = new Date(); var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); </script> </head> <body> <form> <input type="text" value="Enter Your Nickname" id="nameBox" name='usrname'> <input type="button" value="Go!" id="submit" onclick="putCookie(document.getElementsByTagName('form'));"> </form> </body> </html>
While the specific function name should be putCookies instead of storeValues ββand the function call, you can do this: putCookie (document.getElementsByTagName ('form'));
Inside the function definition, cookie values ββcan be obtained from the form, as shown below: setCookie ("userName", form [0] .usrname.value);
The form element must have the attribute: name = 'usrname'
He will set cookies for your username using the form element.
source share