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

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" : ""; ?>>

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>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.