0

Hi,

I have been trying to get a select menu to work for hours, and everything is working fine but for one little bit, everytime I select from the jump menu and load the same page again, the menu displays the first result that comes from the database instead of the user selection from the drop down.

Is there a way to get the selected option to display (using the code below)? The main portfolio.php page holds the url, and the following code is in an included file called dropdown.php

<select onChange="MM_jumpMenu('parent',this,0)" name="dropdown" id="dropdown"> 
    <?php
    while ($result = $query ->fetch_object()) {
    $dbid=$result->id;
    $portfolioname= $result->name;
    ?>

<option value="portfolios.php?pselect=<?php echo $portfolioname; ?>&albumid=<?php echo $dbid; ?>"><?php echo $portfolioname;   ?></option><?php
        }

    ?></select></span>

Any suggestions are much appereciated, and please let me know if you need further detail.

Thanks

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by rootseire
0

If in your while loop you know which one is the one you want to display add 'selected' to the <option> like so:

<option value="..." selected>

For which you can use the short if-else:

<option value="..."<?php echo ($selected) ? " selected" : ""; ?>>
0

Thanks, got it working eventually!

<?php
while ($result = $query ->fetch_object()) {
$dbid=$result->id;
$portfolioname= $result->name;
?>

<option value="portfolios.php?pselect=<?php echo $portfolioname; ?>&albumid=<?php echo $dbid; ?>" <?php if ($_GET == $portfolioname){ echo "selected";} ?>>

<?php echo $portfolioname; ?></option>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.