Monday 8 April 2019

Fill html select using javascript array

I want to fill a select with and array values. I don't see why my code doesnt work. I am a beginner.This is my script



    var mes = new Array();
for(i = 0; i < 12; i++){
mes[i] = i;
}


var sel = document.getElementById('mes');
for(var i = 0; i < mes.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = mes[i];
opt.value = mes[i];
sel.appendChild(opt);
}


And this is the html select:




 

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...