Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP Sticky form drop down menu

Participant ,
Oct 29, 2009 Oct 29, 2009

I need to make this "sticky" (if a user makes a choice and the form is submitted then make the form remember the choice) and cannot figure out how to code it.

<select name="merchantCategoryID" id="merchantCategoryID" >

               <option value="">Please choose a category</option>

                <?php

               do { 

                ?>   

                <option value="<?php echo $row_getStoreCategories['merchantCategoryID']?>"

                <?php

                         if ($row_getStoreCategories['merchantCategoryID']==$row_getMerchant['merchantCategoryID']) {

                              echo "selected=\"selected\"";

                         } ?>>

                         <?php echo $row_getStoreCategories['Category']?></option>

                         <?php

                         } while ($row_getStoreCategories = mysql_fetch_assoc($getStoreCategories));

                           $rows = mysql_num_rows($getStoreCategories);

                           if($rows > 0) {

                               mysql_data_seek($getStoreCategories, 0);

                                $row_getStoreCategories = mysql_fetch_assoc($getStoreCategories);                        }

?>

</select>

TOPICS
Server side applications
4.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 29, 2009 Oct 29, 2009

How is the form being submitted (GET or POST), and what does it do when submitted?

At the moment, it's set to display the value stored in the database.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 29, 2009 Oct 29, 2009

This is the full page of code. I believe I adapted this from your book CS4, Dreamweaverm CSS, PHP. I have for both version CS3 and CS4

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 29, 2009 Oct 29, 2009
This is the full page of code. I believe I adapted this from your book CS4, Dreamweaverm CSS, PHP. I have for both version CS3 and CS4
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 29, 2009 Oct 29, 2009
This is the full page of code. I believe I adapted this from your book CS4, Dreamweaverm CSS, PHP. I have for both version CS3 and CS4
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2009 Oct 30, 2009

You want to display the value selected if the form contains errors, so you just need to check if $_POST['merchantCategoryID'] has been set, and use it.

<select name="merchantCategoryID" id="merchantCategoryID">
   <option value="">Please choose a category</option>
   <?php
   do { 
   ?>
   <option value="<?php echo $row_getStoreCategories['merchantCategoryID'];

      if (isset($_POST['merchantCategoryID']) &&

      $_POST['merchantCategoryID'] == $row_getStoreCategories['merchantCategoryID']) {

         echo 'selected="selected"';

      }?>"><?php echo $row_getStoreCategories['Category']?></option>
   <?php } while ($row_getStoreCategories = mysql_fetch_assoc($getStoreCategories));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2013 Jan 09, 2013
LATEST

So how can I make a select/list field sticky on an input form, not via an SQL query? There must be a way but I haven't found it. Using the above as an example, how would it be modified to refer to a "month" field, id="select1". Please help! Thanks.  tedra

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines