0

I have an input checkbox field and when the checkbox changes (user clicks or unclicks) the div below should toggle. In my style sheet I have the div paypalInputArea as display:none and when the checkbox in clicked, it should toggle, however I can't seem to get it to work. Can anyone see what is wrong with my code?

Here is my html:

<div class="checkbox-row" id="paypalCheckbox">
<input type="checkbox" maxlength="2147483647" value="true" name="paypalPaymentCheckbox" id="paypalPaymentCheckbox" class="checkinput styled" />
<label class="paymentMethodTitle"></label>
</div> 

<div class="paypalInputArea">
    <isinclude template="includes/paymentmethodsinclude" /> 
</div>

And here is my jQuery:

 $("#paypalCheckbox.checkbox-row .areaExpander").on('change', function() {
                $(".paypalInputArea").toggle();
                if ($('.paypalInputArea').is(':visible')) {
                    app.paymentAndReview.setCOContinueBtn(true);
                    $("#paypalPaymentCheckbox").attr('checked','true');
                    $('#paypalCheckbox.checkbox-row .areaExpander').addClass('open');
                } else {
                    $("#paypalPaymentCheckbox").removeAttr('checked');
                    $('#paypalCheckbox.checkbox-row .areaExpander').removeClass('open');
                    app.paymentAndReview.setCOContinueBtn(false);
                }
            });
            $("#paypalCheckbox.checkbox-row input").attr('checked') && app.paymentAndReview.setCOContinueBtn(true);
1
  • Please upload a sample fiddle so we can check it, it is not a whole code, as i am unable to find a class name areaExpander Commented Jul 17, 2018 at 5:15

2 Answers 2

1

$("#paypalCheckbox").on('change', function() {
        $(".paypalInputArea").toggle();
        if ($('.paypalInputArea').is(':visible')) {
            //app.paymentAndReview.setCOContinueBtn(true);
            $('#paypalCheckbox.checkbox-row .areaExpander').addClass('open');
        } else {
            $('#paypalCheckbox.checkbox-row .areaExpander').removeClass('open');
            //app.paymentAndReview.setCOContinueBtn(false);
        }
    });
    $("#paypalCheckbox.checkbox-row input").attr('checked') && app.paymentAndReview.setCOContinueBtn(true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="checkbox-row" id="paypalCheckbox">
    <input type="checkbox" maxlength="2147483647" value="true" name="paypalPaymentCheckbox" id="paypalPaymentCheckbox" class="checkinput styled" />
    <label class="paymentMethodTitle"></label>
</div> 

<div class="paypalInputArea" style="display:none">
    blabla
</div>

just replace the line:

$("#paypalCheckbox.checkbox-row .areaExpander").on('change', function() {

with:

$("#paypalCheckbox").on('change', function() {

As you have an ID (which has to be unique) you dont have to use other classes or else to reach it!

you can also remove those lines as the attrribute checked is set as the user clicks on the checkbox

$("#paypalPaymentCheckbox").attr('checked','true');
$("#paypalPaymentCheckbox").removeAttr('checked');

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you're missing the class areaExpander from your checkbox

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.