Jump to content

[SOLVED] Dropdown selection from variable


Andy17

Recommended Posts

Hey guys, I was wondering how I can get my dropdown box to select a certain value based on a variable. If you do not know what I mean, let me give you an example:

 

<?php

$category = "Classic";

?>

<form name="blabla" method="post">

<select name="category">

<OPTION>Adult</OPTION>
<OPTION>Alcohol</OPTION>
<OPTION>Bar</OPTION>
<OPTION>Blonde</OPTION>
<OPTION>Brunette</OPTION>
<OPTION>Classic</OPTION>
<OPTION>Men</OPTION>
<OPTION>Sports</OPTION>
<OPTION>Women</OPTION></select>

</form>

 

In the example above, I would like "Classic" to be preselected in the dropdown box when the page loads, because $category = "Classic". If $category was = "Blonde", then I would obviously want "Blonde" to be preselected. Is there a simple way to do this?

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/126896-solved-dropdown-selection-from-variable/
Share on other sites


<OPTION <?php if($var == adult){ echo selected="selected"; } ?>>Adult</OPTION>
<OPTION>Alcohol</OPTION>
<OPTION>Bar</OPTION>
<OPTION>Blonde</OPTION>
<OPTION>Brunette</OPTION>
<OPTION>Classic</OPTION>
<OPTION>Men</OPTION>
<OPTION>Sports</OPTION>
<OPTION>Women</OPTION>

 

Something like that going all the way down should do it, I believe. :]

 

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.