Tim
Tim

Reputation: 1074

HTML - Numbers in Select Dropdown Menu

I have an HTML page (index.php) with a drop down menu that contain numbers 1-20. Is there a simpler way of adding the options to the drop down menu rather than just adding each manually like:

<option value=1>1</option>
...
<option value=20>20</option>

Upvotes: 1

Views: 1909

Answers (2)

fkerber
fkerber

Reputation: 1042

As you already mention php in your tags, then using a for-loop when generating the web page would be possible:

for ($i = 1; $i<=20; $i++) {
    echo '<option value="'.$i.'">'.$i.'</option>';
}

You should further think about spending some more quotes to the value attribute as in my code above.

Upvotes: 4

WayneC
WayneC

Reputation: 5740

Easiest would be a for loop :

<?php for ($i = 1; $i <=20; $i++) : ?>
    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>

Upvotes: 0

Related Questions