Wednesday 15 January 2014

javascript - input remembered without using a form -


If I use a form and submit a button, then the browser can remember the text input fields, but if I use only input types, there is no form and the button action is an onclick event, the browser does not cache the input value for the user.

Is there a way to cache "form" input even without actually submitting the browser?

Below is the sample code, showing my page when the user clicks on the search, the JavaScript function is called that it will pop out the div "result" works everything except any browser text input Will cache.

  & lt; H2 & gt; Device Cleaner & lt; / H2 & gt; & Lt; P & gt; Enter the MAC address of the device to clear: & lt; / P & gt; & Lt; Input type = "text" id = "entry" name = "maccode" onkeypress = "keyChecker (event)" & gt; & Lt; Button type = "button" id = "start" onclick = "query ()" & gt; Search & lt; / Button & gt; & Lt; Div id = "result" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

It is not possible to force the browser to save this information. Unless the input you want to save is relatively low, you can use javascript to store cookies with this information. Then while viewing the page in the future, you can use these cookies to fill the input fields. However beware of sensitive information.

Alternatively, you can store user input on your own server through AJAX requests.

No comments:

Post a Comment