...

View Full Version : SELECTED in drop down



basketmen
10-27-2011, 10:06 PM
Hi guys, i have a drop down code below




<select class="input" name="mod[cpu]">
<option value=""> </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

the output are like this

$html .= ($content[cpu] ? '<div class="' . $this->switch_bg() . '"><strong>CPU:</strong> ' . @htmlspecialchars($content[cpu]) . '</div>' : '');




i want after the drop down choosed by user, it will add SELECTED next time they opening the drop down again

i am still dont know how to put the SELECTED there, please help what is the code to add SELECTED, i only have variable mod[cpu] and $content[cpu]


i already tried in bold below, but still not working


<select class="input" name="mod[cpu]" selected="$content[cpu]">
<option value=""> </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>





please share your knowledge

hdewantara
10-28-2011, 03:43 PM
You might get more responses by posting this to PHP subforum..?

And how is $content[cpu] related to mod[cpu]? Well just guessing... you probably want something like the following:


<select class="input" name="mod[cpu]">
<option value=""> </option>
<?php
for ($i=1;$i<4;$i++){
if ($i==$content[cpu]){
echo '<option value="'.$i.'" selected="selected">'.$i.'</option>';
}
else{
echo '<option value="'.$i.'">'.$i.'</option>';
}
}
?>
</select>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum