javascript on click function
Permalink
I've some code on a form that successfully adds shows two hidden attributes and also adds a required class on both upon a check box being clicked. When it is unchecked nothing happens. What's missing?
$('.recruite_to_team input').click(function(){ if( $('.recruite_to_team input').is(':checked') ){ $('.attendee_email').show(); $('.team_code').show(); $('.team_code .input').addClass('required'); var reqd = $('.team_code .input').find('.required_indicator').html(); if(!reqd){ $('.team_code .input').prepend(' <i class="required_indicator">*</i>'); $('.attendee_email .input').addClass('required'); var reqd = $('.attendee_email .input').find('.required_indicator').html(); if(!reqd){ $('.attendee_email .input').prepend(' <i class="required_indicator">*</i>'); }
Viewing 15 lines of 25 lines. View entire code block.
Try something like this:
Viewing 15 lines of 24 lines. View entire code block.
Thanks. Unfortunately I get the same end result as with the original code. That is when I uncheck the box the fields stay appearing, but when I check the box again the fields disappear.
> On 12 Oct 2017, at 17:30, concrete5 Community <discussions@concretecms.com> wrote:
> On 12 Oct 2017, at 17:30, concrete5 Community <discussions@concretecms.com> wrote:
Put an "alert('hello there');" into the "else" and see if it gets there. If it does, you need some code changes within the else. Not sure what you're trying to do here with all these classes and such so, probably best to do a thing like that.
The alert does appear, but only when I've unchecked, and then checked the box again.
Text Deleted as it referenced a deprecated jquery function..
Sorted. There was an extra } in the code. I've removed and it's all working.