...

View Full Version : selectbox



js17
03-24-2009, 01:36 PM
Hi All,I am new to javascript.i want to know how can i generate selectbox dynamically using javascript.

what i mean is
for(int i=0;i<10;i++)
{
<select name="list" id="listid"><option>1</option></select>
}
every time i have to change the id of select tag.Any suggestions?

Thank You

Philip M
03-24-2009, 02:45 PM
This should point the way:-


<body onload = "load_combo ('sel_planet', planets)">

<select id= "sel_planet">
</select>

<script type = "text/javascript">

var planets = new Array ("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto");

function add_option (select_id, text) {
var select = document.getElementById(select_id);
select.options[select.options.length] = new Option(text);
}

function load_combo (select_id, option_array) {
for (var i = 0; i < option_array.length; i++) {
add_option (select_id, option_array[i]);
}
}

</script>

for(int i=0; i<10; i++) is incorrect syntax. Should be
for(var i=0; i<10; i++)


Tourist in Athens to tour guide: "You have told us something about Byzantine architecture. Would it be possible to meet some Byzants?"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum