Sergi Khizanishvili Sergi Khizanishvili - 14 days ago 5
HTML Question

One <option> List For Several <select> Elements

Is it possible to define one dropdown list in html and use it for several forms on one page?

I have this dropdown form:

<select name="test1" id="test1">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>


And I will have much more forms like this but with the same list. like:

<select name="test2" id="test2">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

<select name="test3" id="test3">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>


My question: Is it possible to use one dropdown list for all forms? So I didn't have to copy each one? (there will be more than 200 lines in dropdown list)

Answer

I assume your server accepts PHP (normaly does)...

write this script and save it as: myoption.php

<?php
echo 
'<select name="test1" id="test1">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>';
?>

then make an php-include at the desired point of your script and save this as yourformname.php

<?php
    include ("myoption.php");
?>
Comments