Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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));
Copy link to clipboard
Copied
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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more