Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   SELECTED in drop down (https://www.warriorforum.com/programming/477017-selected-drop-down.html)

basketmen 27th October 2011 02:09 PM

SELECTED in drop down
 
Hi guys, i have a drop down code below



Quote:

<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
Quote:

$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

Quote:

<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

shabtay 27th October 2011 11:43 PM

Re: SELECTED in drop down
 
what do u have in $content[cpu]??

any way... selected should be in the option tag and not in the select tag...

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

Tim Brownlaw 28th October 2011 11:11 PM

Re: SELECTED in drop down
 
1 Attachment(s)
Quote:

i want after the drop down choosed by user, it will add SELECTED next time they opening the drop down again
This would require either saving the information in a Database and retrieving it on redisplaying the page or using a session.

Either way the option list needs to be generated in say PHP where it inserts the selected field in the appropriate entry so it appears as the chosen field.

Here's a little demo which just demonstrates the use of a form with a select box. It might help you, but it seems you need a little more understanding of what you are currently using in your script...

I've included a PDF with some explanation and the demonstration script.
Hope that helps!


All times are GMT -6. The time now is 03:27 AM.