LukeJonGibson LukeJonGibson - 2 months ago 34
HTML Question

Easy way to add drop down menu with 1 - 100 without doing 100 different options?

I was just wondering if there was a simple shortcut to add options to a dropdown menu for the numbers 1 to 100 instead of having to do the following:

<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>


etc. all the way to 100?

Thanks

Answer

Not with plain HTML I'm afraid.

You could use some jQuery to do this though:

$(function(){
    var $select = $(".1-100");
    for (i=1;i<=100;i++){
        $select.append($('<option></option>').val(i).html(i))
    }
});‚Äč

-- SEE DEMO --

You can download jQuery here