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>

Recommended Answers

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>
Jump to Post

All 2 Replies

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>

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

Many thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.