0

I would like a default selected value only if there is no data shown from the echo syntax. Can I get some assistance ? I've tried adding the "Selected" option but that just overrides the current data if any exist. Here is snippet of code is currently looking.

<td><div align="right"><strong>OUTPUT&nbsp;</strong></div></td>
<td><div align="left"><select name="OUTPUT" id="OUTPUT">

                                                            <option value="<? echo $output_id; ?> "><?php echo $output_status; ?></option>
                                                            <option value="1">Not Required</option>
                                                            <option value="2">Not Applicable</option>
                                                            <option value="3">Unknown</option>
                                                    </select></div></td>
74i8Un3
  • 29
  • 6

1 Answers1

3

Changing your first option to the following will do the trick:

<option <?php echo (empty($output_id) ? "selected='selected'" : ""); ?> value="<?php echo $output_id; ?> "><?php echo $output_status; ?></option>

If the value of $output_id is empty the option will be set to selected.

Casper André Casse
  • 573
  • 2
  • 8
  • 20