0
Good afternoon, I’m racking my brain to fix this, someone could help?
I have a textarea in which the user will paste the data from an excel spreadsheet, the data enter as follows:
10 | produto1 | 1 | 3
20 | prodto2 | 2 | 4
These Pipes do not go in the textarea I put to separate better here
I take this data and use split() to remove the spaces and save the data in an array.
After that I want to insert this data into a table, with the respective columns, if I place a row only in the textarea, it works, if I put more than one I don’t know how I do to 'break' the row in the table. Follow my script below:
addItens = function() {
var valor = document.getElementById('texto').value;
var retorno = valor.split(" ");
var newRow = $("<tr>");
var cols = "";
for(i = 0; i < retorno.length; i++)
{
cols += '<td>'+retorno[i]+'</td>';
}
cols += '<td class="actions">';
cols += '<button class="btn btn-large btn-danger" onclick="RemoveTableRow(this)" type="button">Remover</button>';
cols += '</td>';
newRow.append(cols);
$("#products-table").append(newRow);
return false;
};
})(jQuery);
If you put a line only in the textarea, it gives right in the tb, but if you put more than one line, it doesn’t work anymore? What happens? is all in one row only? Or don’t you know in the array when it’s a new record? Type a record of a new textarea line?
– Aline