tags:

views:

1041

answers:

2

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 ...];
    });
});
+4  A: 

Oops, it's

$('#mySelect').attr('size', value)
Loren Segal
+1  A: 
$("#mySelect").bind("click", function(){
    $("#myOtherSelect").children().remove();
    var myArray = [ "value1", "value2", "value3" ];
    for (var i = 0; i < myArray.length; i++) {
     $("#myOtherSelect").append( '<option value="' + myArray[i] + '">' + myArray[i] + '</option>' );
    }
    $("#myOtherSelect").attr( "size", myArray.length );
});
hal10001