Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Bootstrap - Only Expand/Collapse with Specific Radio Button Clicked

I am trying to create some website functionality where there are two radio buttons "Yes" and "No", and when "Yes" is selected, it expands the collapsible portion of HTML, and when "No" is selected, it collapses it. The issue I am running into is if you continuously click the "Yes" radio button, it will expand and collapse it. I only want one or the other depending on which button is selected. This is what I have come up with:

HTML:

        <div class="row gy-3">
            <label><b>Have you ever applied for a job with any of the companies listed above as an employee or as a temporary employee? *</b></label>
                <div class="col-md-4">
                    <div class="form-check">
                        <input type="radio" class="form-check-input" id="validationFormCheck2" name="radio-stacked" value="Yes" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample" required>
                        <label class="form-check-label" for="validationFormCheck2">Yes</label>
                    </div>
                    <div class="form-check mb-3">
                        <input type="radio" class="form-check-input" id="validationFormCheck3" name="radio-stacked" value="No" required>
                        <label class="form-check-label" for="validationFormCheck3">No</label>
                        <div class="invalid-feedback">More example invalid feedback text</div>
                    </div>
                    <div class="collapse" id="collapseExample">
                        <div class="card card-body">
                            Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
                        </div>
                    </div>
                </div>
            </div>

JS:

$('#employmentForm input').on('change', function() {
   var value = $('input[name=radio-stacked]:checked', '#employmentForm').val();
   if (value === "Yes") {
       var myCollapse = document.getElementById('collapseExample')
       var bCollapse = new bootstrap.Collapse(myCollapse, {
         show: true
       })
   } else if (value === "No") {
       var myCollapse = document.getElementById('collapseExample')
       var bsCollapse = new bootstrap.Collapse(myCollapse, {
           dispose: true 
       })
   }
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!