javascript - How to get radio button value from first page to second page using localstorage / ajax jquery -


currently working on local storage in first page have 2 radio buttons if user select first radio button in second page panel has hide. , if user select radio button 1 text field second page validation should not happen have no idea how use localstorage or ajax 1 best

when saw got window.localstorage.setitem("key_name", "stringvalue");

kindly guide me how use :

first page code

<!doctype html> <html> <head> <script src="https://code.jquery.com/jquery-1.11.3.js"></script>   <meta charset="utf-8">   <title>first page</title> </head> <body>  <form id="first_pge" class="first_pge" action="second.page"> <input type="radio" name="radio" id="first_radio"/>   <input type="radio" name="radio" id="second_radio"/>   <input type="button" value="submit" id="btn_sub"/>   </form </body> </html> 

second page

<!doctype html> <html>   <head>     <script src="https://code.jquery.com/jquery-1.11.3.js"></script>     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js"></script>     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/additional-methods.min.js"></script>     <script>             jquery.validator.setdefaults({                     debug: true,                     success: "valid"             });             $("#myform").validate({                     rules: {                             field: {                                     required: true                             }                     }             });     </script>     <meta charset="utf-8">     <title>js bin</title>     <style>             .div_panel {                     background-color: yellow;                     font-size: 16px;             }     </style>  </head>  <body>     <form id="myform" class="myform">             <div class="div_panel">first</div>             <div>&nbsp</div>             <input type="text" id="field" class="field" />             <input type="button" required value="submit" id="btn_sub1" />     </form>    </body>  </html> 

currently working jquery per below user helped me.

in first page setting

            storedata();         function storedata()             {                 alert("check");                 localstorage.setitem('pg', $('#basicform #pg').attr('checked', 'checked'));                 //alert("yes" + getd);                 localstorage.setitem('cu', $('#basicform #cu').attr('checked', 'checked'));             } 

when setting in second page default particular div hiding if user open second page directly :(

kindly please me

if( localstorage.getitem('pg') ) {     $('#edu_info').hide(); } 

take @ html5 local storage, it's realy easy use.

i think have add onsubmit() in form , store values want in localstorage , in second page can them using localstorage.getitem().

add in form onsubmit event call function called storedata() add radio buttons values localstorage:

<form id="first_pge" class="first_pge" action="second.page" onsubmit="storedata()"> 

add function storedata() :

<script>     function storedata()     {         localstorage.setitem('first_radio', $('#first_pge #first_radio').is(':checked'));         localstorage.setitem('second_radio', $('#first_pge #second_radio').is(':checked'));     } </script> 

now have value of both radios , can use them in second page using getitem() :

if( localstorage.getitem('first_radio') ) {     $('.div_panel').hide(); } 

like if first radion in first page checked panel hidden.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -