Created
September 7, 2012 21:21
-
-
Save nicwolff/3669759 to your computer and use it in GitHub Desktop.
Bookmarklet to store and fill in a test form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:V=JSON.parse(localStorage['formData']||'{}');M={};F=document.forms;for(i=0;i%3CF.length;i++){E=F[i].elements;for(j=0;j%3CE.length;j++){C=E[j];CT=C.type;if(!C.name||CT=='submit'||CT=='hidden')continue;CN=C.name+':'+(M[C.name]=(M[C.name]||0)+1);CR=CT=='checkbox'||CT=='radio';if(CR&&V[CN]==true)C.checked=true;if(V[CN]&&!CR&&!C.value&&!C.selectedIndex){if(CT=='select-one'){for(k=0;k%3CC.options.length;k++){if(C.options[k].value==V[CN]){C.selectedIndex=k}}}else{C.value=V[CN]}}if(C.value=='-')C.value='';V[CN]=(C.options&&C.selectedIndex%3E-1&&C.options[C.selectedIndex].value)||(CR?C.checked:C.value);}}void(localStorage['formData']=JSON.stringify(V)); |
Still working on checkboxes...
Saves checkboxes and radio button groups now
Doesn't handle multiple select controls, but when's the last time you used one of those?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now handles multiple fields with same name