javascript - How to keep input status when click back button? -



javascript - How to keep input status when click back button? -

click reset button on page test1, input of id become enabled. edit value , click submit button, , go page test2. click button homecoming page test1. problem is, input keeps edited value status disabled. want maintain enable. how solved problem. (it works on firefox not work on ie , chrome.)

class="snippet-code-html lang-html prettyprint-override"><html> <head> <title> test1 </title> <script type="text/javascript"> function setenable(){ document.myform.id.disabled = false; } </script> </head> <body> <form method="post" name="myform" action="test2.html"> <input type=text name="id" value="test" disabled/> <input type=button value="reset" onclick=setenable(); /> <input type=submit /> </form> </body> </html>

class="snippet-code-html lang-html prettyprint-override"><html> <head> <title> test2 </title> </head> <body> <input type=button value="back" onclick=history.back(); /> </body> </html>

there 2 ways accomplish this:

1) can accomplish js , cookies...

https://developer.mozilla.org/en-us/docs/web/api/document.cookie

the thought create cookie when user leaves page saving form data, , when same page loaded again, check if there cookie , if set form fields cookie data....

it's pretty simple @ couple examples.

2) coordinate form server using php or ajax , have page rendered context containing info first submit , repopulating form context data

javascript html

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -