I have a PHP code that actively generates a Select input with 5 different options in it.
Now, I also want to show the number 2, 3, 4 and 5 in a div as text as well.
Note that I want to ommit the first option in my DIV.
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
Also to be displayed accordingly:
<div><img src="#" /> 2</div>
<div><img src="#" /> 3</div>
<div><img src="#" /> 4</div>
<div><img src="#" /> 5</div>
I tried doing this with document.forms[0].select.value; but it only shows the selected value and not all the options. Furthermore, I want to filter the first option so what should I do? Any help is appreciated.
Actual HTML of the select element, provided by OP in comments to an answer:
<select class="last" id="property_types" name="property_types">
<option selected="selected" value="0">View all Property Types</option>
<option value="96" class="level-0">Apartment</option>
<option value="9" class="level-0">Building</option>
<option value="3" class="level-0">Land</option>
<option value="97" class="level-0">Office</option>
</select>
I’d suggest:
JS Fiddle demo.
Note that this assumes a specific
divis used in order to contain the output of this approach, obviously adjust to taste.Above code amended to provide a specific selector, in response to the OP’s posting code in the comments to this answer:
References:
appendTo().each().prependTo().slice().