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