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

  • Home
  • SEARCH
  • 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 5959893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:44:56+00:00 2026-05-22T18:44:56+00:00

I have a SELECT input that gets all of its options via the database.

  • 0

I have a SELECT input that gets all of its options via the database. Below the select input, there are divs created for each option in the select. I want the user to select an option from the drop down and make the div below display. So basically the drop down are sports, and if they make a selection the sport div hidden below will load, and that div will contain all the sport positions

 <select name="sport" id="select">
    <?
    foreach ($getSports as $row) {
        echo '<option onClick="toggle'.$row['1'].'()" onLoad="toggle'.$row['1'].'()" value="' . $row['0'] . '">' . $row['1'] . '</option>';
    }
    ?>

                </select>
            </label>
           <?
    foreach ($getSports as $row) {
        echo '<div id="position' . $row['1'].'" style="margin-top: 5px;display:none;">Positions:' . $row['1'].'';
        $sport = $row['0'];
            $getPositions = $model->getPositions($sport);
            foreach ($getPositions as $row2) {
                echo '<label style="float:right">'.$row2['1'].'</label>';
               echo '<input type="checkbox" name="'.$row2['1'].'" value="'.$row2['0'].'">';
            }

        echo '</div>';
    }
    ?>
  • 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-05-22T18:44:57+00:00Added an answer on May 22, 2026 at 6:44 pm

    How about modifying your code like this? Seems to be more semantic:

        <select name="sport" id="select">
        <? foreach ($getSports as $row) {
            echo '<option data-row-id="'.$row['1'].'" value="'.$row['0'].'">'.$row['1'].'</option>';
        } ?>
        </select>
    </label>
    
    <? foreach ($getSports as $row) {
        echo '<div data-position="'.$row['1'].'" style="margin-top:5px;display:none;">Positions:' . $row['1'].'';
            $sport = $row['0'];
            $getPositions = $model->getPositions($sport);
            foreach ($getPositions as $row2) {
                echo '<label style="float:right">'.$row2['1'].'</label>';
                echo '<input type="checkbox" name="'.$row2['1'].'" value="'.$row2['0'].'">';
            }
    
        echo '</div>';
    }?>
    
    
    <script>
    $(function() {//create the binding once the document is ready
        $('#select').change(function() {
            var select = $(this);
            var selectedOption = select.find(':selected');
            var position = selectedOption.attr('data-row-id');
            var divContext = $('[data-position="'+position+'"]');
    
            $('[data-position]').not(divContext).hide();
            divContext.show();
        });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an html form. Each input/select/textarea will have a corresponding <label>
Suppose I have a SELECT statement that returns some set of results. Is there
I have a form that has a select menu(A) and 2 divs (B and
I have a list of options that looks like this: <select id=input_13> <option class=level-1
I have a select query that currently produces the following results: Description Code Price
I want to have a select-only ComboBox that provides a list of items for
I have a radio button set called pick_up_point. There are 3 options and clicking
I have a form where there are 6 items, each of which can be
So i have a page that is gonna have multiple modal popups. Each one
I have a select input on my page. this select input displays/hides fields in

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.