Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8147469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:21:47+00:00 2026-06-06T14:21:47+00:00

I am populating a list of checkboxes from a foreach loop, and giving each

  • 0

I am populating a list of checkboxes from a foreach loop, and giving each an ID. I have added a set of divs below that would appear, depending on which checkbox is created. I was thinking I could load the id variable into a jQuery if statement, and then use a .toggle to show or hide the corresponding div.

<?php 
//Call Programs
$getPrograms = Doctrine::getTable('Program')->createQuery()->where('subsection=?', 'mfa')->orWhere('subsection=?', 'mps')->orWhere('subsection=?', 'mat')->orWhere('subsection=?', 'ma')->orderBy('title ASC')->execute(); ?>

    <div class="form_row">
     <label>
    <span><sup class="required_form_item">*</sup>Select Program</span>
    </label>
        <div class="buttonColumn" style="margin-left:170px;">
        //loop the records in with checkboxes
        <?php foreach ($getPrograms as $prog): ?>
              <?php 
              $subsection = $prog->getSubsection();
              $subsection = strtoupper($subsection);

              $trimProg = trim($prog->getTitle(), ' ');
              $removeChars = array(" ", "&");
              $trimProg = str_replace( $removeChars, '', $trimProg ); 
              $trimProg = preg_replace('/\s\s+/', '_', $trimProg);

              ?>
              //custin id matches record title
              <input type="checkbox" name="program" class="isChecked" id="<?php echo $trimProg; ?>" value="<?php echo $subsection . " " . $prog->getTitle() ?>" /><?php echo $subsection . " " . $prog->getTitle() ?><br />
        <?php endforeach ?>
        </div>
    </div> 

The following divs would be set to display:none until the matching checkbox is checked.

    <div class="form_row sessionTime" id="Program1" style="display:none;">
    Please choose an session time:
    <input type="checkbox" name="schedule" value="5:00 pm" />5:00 pm<br />
    </div>

    <div class="form_row sessionTime" id="program2" style="display:none;">
    Please choose an session time:
    <input type="checkbox" name="schedule" value="10:00 pm" />10:00 pm<br />
     </div>    
    ...

And this is what I thought would work…but alas…it doesn’t

$('.isChecked').click( function() {

    if ( $(this).is(':checked') ) {
      $thisID = $(this).attr("id");
      $('.'+ $thisID).show();
    }
    else {
      $('.'+ $thisID).hide();
    }
  }
); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:21:49+00:00Added an answer on June 6, 2026 at 2:21 pm

    You should be using “Program1” as class name instead of id like this

    <div class="form_row sessionTime Program1" style="display:none;">
      Please choose an session time:
      <input type="checkbox" name="schedule" value="5:00 pm" />5:00 pm<br />
    </div>
    

    And your jQuery code should work, which you can simplify as follows:

    $('.isChecked').click( function() {
      if ( $(this).is(':checked') ) {
        $('.'+ this.id).show();
      }
      else {
        $('.'+ this.id).hide();
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a dropdownlist that populates from the sql server database. populating the list
I have a ComboBox that I am populating with a list of parts for
I am populating a list of names that will be added to my Sql
I currently have this code for populating a list of comments to return: foreach
I have an activity that has two tabs and a list view in each.
I am populating the list view with data I am getting from a JSON
I have a problem with populating an autocomplete list based on a previous input.
Im populating a GridView from List so am forced to use TemplateField controls to
I have a Jstree populating a list of items. When I click a node
I have a ListView-like control that displays a list of items of various heights.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.