jquery - save form fields after refresh page -
i have form 3 hide fields. when click buttons
<div class="buttons"> <button id="but-1">1</button> <button id="but-2">2</button> <button id="but-3">3</button> <button id="but-4">4</button> </div>
some fields hide show
my form
<div class="form"> <div class="pass-1 form_pass"> <p><span>pass1:</span><input id="catalogs_pass_1" name="catalogs[pass_1]" type="text" /></p> </div> <div class="pass-2 form_pass" style="display: none;"> <p><span>pass2:</span><input id="catalogs_pass_2" name="catalogs[pass_2]" type="text" /></p> </div> <div class="pass-3 form_pass" style="display:none;"> <p><span>pass3:</span><input id="catalogs_pass_3" name="catalogs[pass_3]" type="text" /></p> </div> <div class="pass-4 form_pass" style="display:none;"> <p><span>pass4:</span><input id="catalogs_pass_4" name="catalogs[pass_4]" type="text" /></p> </div> <div class="form_pass"> <p><span>phone:</span><input id="catalogs_phone" name="catalogs[phone]" type="text" /></p> <p><span>email:</span><input id="catalogs_email" name="catalogs[email]" type="text" /></p> <p><input class="submit-rez" id="catalogs_submit" name="commit" type="submit" value="submit" /><p> </div>
all works fine, when users not pass validation on field page refreshes , shown fields disappear. how save shown fields?
i used cookie plugin , create save fields 1 button. how create save cookie other 3 buttons?
thanks advice!
try
$(document).ready(function () { $('#but-1').click(function () { $('.pass-1').fadein(300); $('.pass-2').fadeout(100); $('.pass-3').fadeout(100); $('.pass-4').fadeout(100); $.cookie('content1', 1); }); $("#but-2").click(function () { $(".pass-2").show(); $(".pass-3").hide(); $(".pass-4").hide(); $.cookie('content1', 2) }); $("#but-3").click(function () { $(".pass-2").show(); $(".pass-3").show(); $(".pass-4").hide(); $.cookie('content1', 3) }); $("#but-4").click(function () { $(".pass-2").show(); $(".pass-3").show(); $(".pass-4").show(); $.cookie('content1', 4) }); if ($.cookie('content1')) { var pass = parseint($.cookie('content1')); for(var = 1; <= pass; i++) { var str = "pass-"+i; $("."+str).show(); } }; });
note: have chnaged jquery.cookies url. don't load github. give plain text file.
Comments
Post a Comment