jquery - Retain radio button state that affects other elements -


i have form lots of inputs. using jquery if person selects answer "yes" text box appears if click "no" nothing appears. problem when person submits page , page runs through php validation if throws page (incurs reload) error while can radio button remember value chosen (using php) not re-show textbox if user clicked yes.

basically: user picks yes, text box shows. user submits page, page thrown due validation error. radio button remembers state "yes" text box not shown unless re clicking yes.

any idea how can textbox show up?

jquery

$("input[name='radiobutton']").change(function(){     if ($(this).val() == "yes")     {         $("#txt1").show();     }     else     {         $("#txt1").hide();      } }); 

you can checked radio button on page load:

$(document).ready(function(){     if($("input[name='radiobutton'][value='yes']").is(':checked'))         $("#txt1").show();     else         $("#txt1").hide();  }); 

edit: changed use ".is(':checked')"


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -