Try putting the bulk of your code in a separate function:

$(function() {
   // do check on document ready
   myFunction();

   // make click work
   $('#Professor').click(myFunction);
});

function myFunction() {
      if ( $('#Professor').get(0).checked ) {
        $('#ProfessorField').show();
        $('#SubscriptionsField').show();
      } else {
        $('#ProfessorField').hide();
        $('#SubscriptionsField').hide();
      }
}


On Feb 24, 3:53 pm, shapper <mdmo...@gmail.com> wrote:
> Hello,
>
> I have the following:
>
>     $('#Professor').click(function(){
>       if ( this.checked ) {
>         $('#ProfessorField').show();
>         $('#SubscriptionsField').show();
>       } else {
>         $('#ProfessorField').hide();
>         $('#SubscriptionsField').hide();
>       }
>     })
>
> Basically on a form I am hiding/showing a few fieldsets when a
> checkbox is selected or unselected.
>
> However, when I submit the form and there are errors, the page is
> displayed again with the error messages.
>
> The problem is that the fields get visible independently of the
> checkbox Professor value.
> I don't know why ... So I added the following:
>
>     $('#Professor').load(function(){
>       if ( this.checked ) {
>         $('#ProfessorField').show();
>         $('#SubscriptionsField').show();
>       } else {
>         $('#ProfessorField').hide();
>         $('#SubscriptionsField').hide();
>       }
>     })
>
> Still does not work ... any idea why?
>
> And since the code is the same can't I join the two events?
>
> Thanks,
> Miguel

Reply via email to