Menu problems

Hi guys

So i am having a problem with the drop down menu

For example, when you click the option “other” from the menu, it will prompt you with an additional text box, as you can see from the script below:



                <tr>
                  <td valign="top" class="formLabelsS2"><div align="right">Genetic Background: </div></td>
                  <td><select name="genetic_bg[]" size="5" multiple="multiple" class="basicMenu" id="genetic_bg"
                          onChange="toggleOther('genetic_bg','GeneticBGOther','GeneticBGOtherTxt');" >
                           <?php
                            menu_display("genetic_bg");
                        ?>
                  </select>
                  </td>
                </tr>
                <tr id="GeneticBGOther"
                <?php menu_display_other("genetic_bg");?>>
                      <td class="formLabelsS2"><div align="right">Other</div></td>
                      <td><span class="body">
                        <input name="GeneticBGOtherTxt" type="text" class="basicTextField" id="GeneticBGOtherTxt" value="<?php echo $_GET['GeneticBGOtherTxt']; ?>" size="35" />
                      </span></td>
                </tr>


The scripts for menu_display and menu_display_other functions are as follow:

   function menu_display($menu_name){
        $menu = menu_get_menu($menu_name);
        if($_SERVER['REQUEST_METHOD'] == 'POST') {
            $method = $_POST;
        } else {
            $method = $_SESSION;
        }
        if(!empty($menu)){
            for($i=0;$i<sizeof($menu);$i++){
                //we add the label for javascript showing and hiding divs
                echo "<option value={$menu[$i]['value']} label=\\"{$menu[$i]['title']}\\"";
                if(is_array($method[$menu_name])){
                    if(in_array($menu[$i]['value'],$method[$menu_name])){
                        echo "selected=\\"selected\\"" ;
                    }
                } else {
                    if($method[$menu_name] == $menu[$i]['value']) {
                        echo "selected=\\"selected\\"" ;    
                    }
                }
                echo ">{$menu[$i]['title']}</option><br />";
            }
        }    
   }
   
   /*
    This function checks if the variable $str
    is in recieved data
    if not the element is hidden

    input: select id
*/
function menu_display_other($menu_name)
{
    $conn = db_connect_2();
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $method = $_POST;
    } else {
        $method = $_SESSION;
    }
    if($menu_name == 'ana_stage'){
        $query = "SELECT STG_OID FROM ana_stage WHERE STG_NAME = 'Other';";
    } else {
        $prefix = get_table_prefix($menu_name);
        $query = "SELECT {$prefix}_ID FROM $menu_name WHERE {$prefix}_NAME = 'Other';";
    }
    $result = $conn->query($query);
    $row = $result->fetch_array();
    $str = $row[0];
    if(isset($method[$menu_name]))
    {
        //check if it is an array
        if(is_array($method[$menu_name]))
        {
            //check if $str is in the array
            if(in_array($str, $method[$menu_name]))
            {
                //return, the element is displayed
                return true;
            }
        }
        //not array
        elseif($method[$menu_name] == $str)
        {
            return true;
        }
    }
    // finally hide the element since $str was not selected as one of the options
    echo "style=\\"display:none\\"";
    $conn->close();
}

Yes the drop down menu works fine in the original script…

UNTIL i transfer these codes into other scripts

I basically use the exact same codes, but somehow the menu is not doing the same thing when I click the “other” option as before in the original script, or in other word, no additional text box is prompted and basically no response what so ever

By the way, i included all the necessary scripts. So what causes this problem?

Any help is appreciated :slight_smile:

Here’s the URL to the page of the menu, so you can sort of visualize more:

http://nagy.mshri.on.ca/Coop_Student/cre/search/Search_Coop_try3.php

As you can see, the genetic background menu in the Advanced Search section works like it is supposed to. When you click the “other” option on the drop down menu there (scroll down to the bottom of the menu), it will prompt you to an additional text box

But if you compare it with the genetic background menu at the bottom in the update mailing list section, when you click “other”, nothing happens…

Again, i used the exact same code (copy and paste pretty much as you can see above) and the script for update mailing list is INCLUDED into the main script of the search page, so all the scripts needed for menu to work are all there

So what’s the problem?

By the way, i removed the submit button for update mailing list cause i am still building the script

Thanks :slight_smile:

This is actually an html/javascript problem: you’ve given your first multi-select box an id of "genetic_bg’, but then when you copy/paste the code your 2nd select box also has the same id, which is a no-no. Same problem with the id of the <tr> that holds the hidden form field.

You need to give those 2 elements different ids, then change the toggleOther() function arguments in the <select> onchange attribute to reflect those changes.

o such a small mistake that i overlooked …

Problem solved

Thanks!