I am trying to load csv/txt
data to load to select
box. I have tried this script and failed to load data to select
which is a multiple
select box
This is my altered script
$("#upload").bind("click", function() {
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.csv|.txt)$/;
if (regex.test($("#fileUpload").val().toLowerCase())) {
if (typeof(FileReader) != "undefined") {
var reader = new FileReader(),
sel = $("<select id='s'>"),
separator = ';',
rows,
rowLength;
reader.onload = function(e) {
rows = e.target.result.split(/[\r\n|\n]+/);
rowLength = rows.length;
for (var i = 0; i < rowLength; i++) {
var row = $("<option>"), cells = rows[i].split(separator), cellLength = cells.length, cell;
for (var j = 0; j < cellLength; j++) {
$(cell).val(cells[j]);
row.append(cell);
}
sel.append(row);
}
$("#dvCSV").html('');
$("#dvCSV").append(sel);
}
reader.readAsText($("#fileUpload")[0].files[0]);
} else {
alert("This browser does not support HTML5.");
}
} else {
alert("Please upload a valid CSV file.");
}
});
This loads blank select box. How load this (option
value and text
must be same)
And to this, I want to skip a row, if any of the column is blank