?
Solved

Dropdown menu urgent help required

Posted on 2006-05-27
2
Medium Priority
?
235 Views
Last Modified: 2006-11-18
Hello,

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">
            <?php
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>
            <?php
} 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);
  }
?>
          </select>
         
//text field to display the username relevant to selected user id
<?php echo $row_rsDD['custUserName']; ?></div>


Thanks in advance.
0
Comment
Question by:south_paw
2 Comments
 
LVL 10

Accepted Solution

by:
ClickCentric earned 2000 total points
ID: 16778172
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>

0
 

Author Comment

by:south_paw
ID: 16779406
A W E S O M E !

Exactly what I was after.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 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