Jump to content

Echo chosen selection in select (drop-down) box


ryanwood4

Recommended Posts

I'm trying to get a select box to show the result stored in a database as the default, but the value="<? echo $repeat?>"> function doesn't work.

 

Example: User selects Repeat, saves there choice, then comes back to change it, it will show No-Repeat, rather than Repeat.

 

       <select name="repeat" size="1" id="repeat" value="<? echo $repeat?>">

        	<option value="no-repeat">No-Repeat</option>
                <option value="repeat">Repeat</option>
        	<option value="repeat-x">Horizontally</option>
        	<option value="repeat-y">Vertically</option>

                </select>

 

Any help is greatly appreciated, it might be so simple, and if it is, I apologise.

Thanks.

<select name="repeat" size="1" id="repeat">
           <option value="no-repeat" <?php echo ($repeat == 'No-Repeat' ? 'selected="selected"' : '');?>>No-Repeat</option>
           <option value="repeat" <?php echo ($repeat == 'repeat' ? 'selected="selected"' : '');?>>Repeat</option>
           <option value="repeat-x" <?php echo ($repeat == 'repeat-x' ? 'selected="selected"' : '');?>>Horizontally</option>
           <option value="repeat-y" <?php echo ($repeat == 'repeat-y' ? 'selected="selected"' : '');?>>Vertically</option>
</select>

Should do the trick

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.