html – Dynamic Size Menu Javascript-ThrowExceptions

Exception or error:

I am new on java script and I have been trying to develop a select menu using java script and HTML. It has to change the size of how many items the select menu will show according to which button is press.
Is there a way to make it dynamically change the size?

Here is what I have so far.

var value = 6;
$("button").click(function() {value = $(this).val();});

var select = document.getElementById("selectNumber");
var options = [];
for ( j = 1; j < value; j++){
        options += j.toString();
for(var i = 0; i < options.length; i++) {
    var opt = options[i];
    var el = document.createElement("option");
    el.textContent = opt;
    el.value = opt;

Here is the HTML portion:

<button id="3" name="3" value="3">3</button>
<button id="4" name="4" value="4">4</button>
<button id="6" name="6" value="6">6</button>

<select id="selectNumber">
    <option>Choose a number</option>

Thanks in advance.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *