Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery, how can I dynamically set the size attribute of a select box?

Tags:

People also ask

How add option tag dynamically to select in jQuery?

Method 1: Append the option tag to the select box The select box is selected with the jQuery selector and this option is added with the append() method. The append() method inserts the specified content as the last child of the jQuery collection. Hence the option is added to the select element.

What is size attribute in select tag?

The size attribute specifies the number of visible options in a drop-down list. If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.

How do I select a selected box using jQuery?

Answer: Use the jQuery :selected Selector You can use the jQuery :selected selector in combination with the val() method to find the selected option value in a select box or dropdown list.


Using jQuery, how can I dynamically set the size attribute of a select box?

I would like to include it in this code:

$("#mySelect").bind("click",
    function() {
        $("#myOtherSelect").children().remove();
        var options = '' ;
        for (var i = 0; i < myArray[this.value].length; i++) {
            options += '<option value="' + myArray[this.value][i] + '">' + myArray[this.value][i] + '</option>';
        }
        $("#myOtherSelect").html(options).attr [... use myArray[this.value].length here ...];
    });
});