Skip to content Skip to sidebar Skip to footer

How To Populate A List Box (combo Box) From A Multi-dimensional Array?

I'm a student in JavaScript and we have an assignment due tonight. I've been working, and re-working, the code for bit. Essentially, I'm struggling with populating a List Box (com

Solution 1:

Use this Code.

<html><head><scripttype="text/javascript">var concertArray = [
            ["Billy Joel", "99", "equal.png"],
            ["Bryan Adams", "89", "higher.png"],
            ["Brian Adams", "25", "lower.png"]
            ];

            functionpopulate(){

                for(i=0;i<concertArray.length;i++){
                    var select = document.getElementById("test");
                    select.options[select.options.length] = newOption(concertArray[i][0], concertArray[i][1]);
                }

            }
        </script></head><bodyonload="populate();"><selectid="test"></select></body></html>

this will help you.....

Solution 2:

extract the data which you want to add in combo box from the array, then use jquery append to add them to the select tag.

<select id="test">
</select>

Iterate through the array & store the data to be added in a variable, say var data, then:

$('#test').append('<option value="'+data+'">'+data+'</option');

Post a Comment for "How To Populate A List Box (combo Box) From A Multi-dimensional Array?"