mardi 14 avril 2015

Attempting to create the same select list multiple times, but only the last select form is populating

I am making multiple lists with the same values. However, when I run this, it only populates the last select form. I don't really know what I'm doing wrong. Any ideas?



<script type="text/javascript">
for(i = 0; i < 10; i++){
var names = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
//window.alert(names[i])
document.write('<tr>');
document.write('<td>');
document.write('<select id=' + names[i] + '></select>');
var textFile = "/names.txt";
var select = document.getElementById(names[i]);
jQuery.get(textFile, function(textFileData) {
var EachName= textFileData.split("\n");
for (var j = 0, len = EachName.length; j < len; j++) {
var option = document.createElement('option');
option.text = option.value = EachName[j];
select.add(option, 0);
};
});
document.write('</td>');
document.write('</tr>');
}
</script>


Thanks


Aucun commentaire:

Enregistrer un commentaire