javascript - Local storage saving every input and checkbox value on a page -


is there way save every input field , checkbox without code? have , it's working great save separate input fields, class="stored" on each:

$(document).ready(function () {     function init() {         if (localstorage["fname"]) {             $('#fname').val(localstorage["fname"]);         }     }     init(); });  $('.stored').change(function () {     localstorage[$(this).attr('name')] = $(this).val(); });  <div class="form-group required">     <label class="label_fn control-label" for="fname">first name (required):</label>     <input id="fname" name="fname" type="text" placeholder="" class="input_fn form-control stored">     </div> 

but there way to, say, set class of "something-container" on container div , using script base, save input fields storage , have them remain populated in fields until user clears session?

yes, change selector in change event ".stored" ".something-container input". in init method you'll want this:

$(".something-container input").each(function () {     $(this).val(localstorage[$(this).attr("name")]) } 

a side note, .change binding should done inside $(document).ready method well.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -