0

Hi

Does anyone know how to make this dynamic field 'sticky'.

The code as it currently stands does not keep the chosen item showing in the field if there is an error in the form. It just default back to nothing

Many thanks

<select name="condo_nm" class="maintextnopad" id="condo_nm">
              <?php
do {  
?>
              <option value="<?php echo $row_rs_condo['condo_name']?>"><?php echo $row_rs_condo['condo_name']?></option>
              <?php
} while ($row_rs_condo = mysql_fetch_assoc($rs_condo));
$rows = mysql_num_rows($rs_condo);
if($rows > 0) {
  mysql_data_seek($rs_condo, 0);
  $row_rs_condo = mysql_fetch_assoc($rs_condo);
 }
?>
              </select>
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by ebanbury
0

You need to check if the posted data has a value and if so if it equals the value in the menu then if it does, mark as selected:

<option value="<?php echo $row_rs_condo['condo_name']?>" <?php if (!empty($_POST['condo_nm']) && $_POST['condo_nm'] == $row_rs_condo['condo_name']) { echo 'selected'; } ?>><?php echo $row_rs_condo['condo_name']?></option>
0

That is great thanks! I have been trying all kinds of selected=selected varieties but forgot the bit in the middle.

Many thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.