Well, there are two ways to go about this. You could send all the data needed in a JSON object and update the checkboxes using JavaScript based upon the selection or you could have the form post back to PHP to generate the new form which effectively refreshes the page.

I'm assuming you have some sort of mechanism for knowing which checkboxes go with which drop-down option(s). You'd basically just want to have a bunch of if statements to catch what the current drop-down is, and create the form based upon it. So something like:

if(!empty($_POST['selectbox1']))
{
    switch($_POST['selectbox1'])
    {
        case 'OC-192':
            $options = array('value'=>'Label', 'value2'=>'Label', 'value3'=>'Label');
            break;
        case 'T3':
            $options = array('value'=>'Label', 'value2'=>'Label');
            break;
    }

foreach($options as $val => $label)
{
    $checkboxes .= '<input type="checkbox" name="subelement" value="'.$val.'" id="cb'.urlencode($val).'"> <label for="cb'.urlencode($val).'">'.$label.'</label>';
}
}

That's a very simple example, but should give you an idea as to how to start.

The JSON version is a little more tricky, but you could essentially just generate all options for every menu item, and use [man]json_encode/man to send the data to the client. Then use a javascript call to inspect the JSON object and iterate over all options related to the selected item. But that's a whole other issue, and one suited for the ClientSide forum 😉

    Thanks for the reply. If I use the refresh page method,

    i) How do I refresh the page (I'm sorry, but I'm sort of new...) ?
    ii) How do I ensure that the checkboxes selected remain after other dropdown menus are changed?

    Also, what is the 'selectbox1', is that supposed to be the drop-down menu?

    I do know which checkboxes go with which drop-down option.

    Could you explain (or perhaps elaborate) on what this does:
    $checkboxes .= '<input type="checkbox" name="subelement" value="'.$val.'" id="cb'.urlencode($val).'"> <label for="cb'.urlencode($val).'">'.$label.'</label>';

    I know it's making the checkboxes... but what does '.=' do? Also, how would I refer to each checkbox?

      To refresh the page, just add an onChange event to the select box:

      <select name="myselectbox" onchange="this.form.submit();">

      Maintaining checkboxes through different changes would require you to have some checks to see that (1) the selection has changed and (2) there are selected checkboxes. You could use sessions here, or modify your form to use AJAX or use a multi-select combobox instead of the drop-down.

      As for what "selectbox1" is in my code, that would be the name of the drop-down box yes.

      The "." in php is a concatenation character. It basically means add on to. So the string $checkboxes will have whatever comes after the ".=" added on to the end of it.

      You would refer to each checkbox via it's name attribute (just like any other form element).

        I tried to make a form using this but could not. I have the code below. Perhaps someone could shed some light onto why it's not working...

        <html>
        <title> PHP form </title>
        <body>
        <form name="dynamic">
        <?php
        if(($_POST['selectbox1'])!="N/A")
        {
            switch($_POST['selectbox1'])
            {
                case "OC-192":	
                   $options = array('port1'=>'Port 1', 'port2'=>'Port 2', 'port3'=>'Port 3');
                    break;
                case "T3":
                    $options = array('value'=>'Label', 'value2'=>'Label');
                    break;
            }
            foreach($options as $val => $label)
            {
                $checkboxes .= '<input type="checkbox" name="subelement" value="'.$val.'" id="cb'.urlencode($val).'"> <label for="cb'.urlencode($val).'">'.$label.'</label>';
        
        }
        } 
        ?>
        </form>
        <select name="selectbox1" onchange="dynamic.submit();">
         <?php
         $slot1 = array("N/A","OC-192", "T3");
         foreach ($slot1 as $slot1) {
         echo'<option';
         if (strcmp($slot1, $slot_1) == 0) {
         echo 'selected="selected"';
         }
         echo ">$slot1</option>";
         }
         ?>
         </select> 
        </body>
        </html>
          Write a Reply...