Dropdown menu urgent help required

Posted on 2006-05-27
Last Modified: 2006-11-18

I have another urgent question, still related to that cursed dropdown menu.  I have the menu working, essentially when a user selects a particular ID from the dropdown menu, the relevant username is populated in a text field nearby.  Here's my problem: in order to populate the textfield, the page needs to reload.  When the page reloads, the user ID defaults back to the 1st entry.   Sooooo when the form is posted, the wrong user id is posted.  

In a nutshell, my question is: how can i set the dropdown menu so that it remembers the last state it was in, that way, when the page reloads, it will still be correct.  Here's my code:

  <select name="selectID" onChange="if (this.selectedIndex > 0) window.location.href = 'orderform.php?custID=' + this.options[this.selectedIndex].value">
do {  
            <option value="<?php echo $row_rsCust['custID']?>"<?php if (!(strcmp($row_rsCust['custID'], $row_rsCust['custID']))) {echo "SELECTED";} ?>><?php echo $row_rsCust['custID']?></option>
} while ($row_rsCust = mysql_fetch_assoc($rsCust));
  $rows = mysql_num_rows($rsCust);
  if($rows > 0) {
      mysql_data_seek($rsCust, 0);
        $row_rsCust = mysql_fetch_assoc($rsCust);
//text field to display the username relevant to selected user id
<?php echo $row_rsDD['custUserName']; ?></div>

Thanks in advance.
Question by:south_paw
    LVL 10

    Accepted Solution

    With this code:

    <option value="<?php echo $row_rsCust['custID']?>"<?php if (!(strcmp($row_rsCust['custID'], $row_rsCust['custID']))) {echo "SELECTED";} ?>><?php echo $row_rsCust['custID']?></option>

    You're doing a strcmp on $row_rsCust['custID'] to $row_rsCust['custID'], so it's always matching

    Change it to: <option value="<?php echo $row_rsCust['custID']?>"<?php if ($row_rsCust['custID'] == $_GET['custID']) {echo "SELECTED";} ?>><?php echo $row_rsCust['custID']?></option>


    Author Comment

    A W E S O M E !

    Exactly what I was after.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now