Hello, I'm trying to find a solution to my problem, I do not understand anything about javascript, but if anyone can help me, I appreciate it. I have the following script that adds new rows in my table whenever I click a button, it works perfectly however each td has a textarea and would like to generate a different name on each line. Does anyone have any suggestions on how I could do this? Here's the script:
<script>
var cadastro2 = {
linha2: '<td align="center"><textarea class="cols3" rows="2" cols="12" style="overflow: hidden" onkeyup="this.style.height=\'24px\'; this.style.height = this.scrollHeight + 1 + \'px\';" onkeydown="this.style.height=\'24px\'; this.style.height = this.scrollHeight - 1 - \'px\';" name="campo1"></textarea></td>'+
'<td align="center"><textarea class="cols3" rows="2" cols="12" style="overflow: hidden" onkeyup="this.style.height=\'24px\'; this.style.height = this.scrollHeight + 1 + \'px\';" onkeydown="this.style.height=\'24px\'; this.style.height = this.scrollHeight - 1 - \'px\';" name="campo2"></textarea></td>'+
'<td align="center"><textarea class="cols3" rows="2" cols="12" style="overflow: hidden" onkeyup="this.style.height=\'24px\'; this.style.height = this.scrollHeight + 1 + \'px\';" onkeydown="this.style.height=\'24px\'; this.style.height = this.scrollHeight - 1 - \'px\';" name="campo3"></textarea></td>'+
'<td align="center"><textarea class="cols3" rows="2" cols="12" style="overflow: hidden" onkeyup="this.style.height=\'24px\'; this.style.height = this.scrollHeight + 1 + \'px\';" onkeydown="this.style.height=\'24px\'; this.style.height = this.scrollHeight - 1 - \'px\';" name="campo4"></textarea></td>'+
'<td align="center" colspan="2"><textarea class="cols4" rows="2" cols="35" style="overflow: hidden" onkeyup="this.style.height=\'24px\'; this.style.height = this.scrollHeight + 1 + \'px\';" onkeydown="this.style.height=\'24px\'; this.style.height = this.scrollHeight - 1 - \'px\';" name="campo5"></textarea></td>'+
'<td align="center" class="semborda"><input type="button" value="-" class="ui-button ui-widget ui-state-default ui-corner-all principal" onclick="javascript:deleteRow2(this.parentNode.parentNode.rowIndex)" title="Remover linha"></input></td>',
adicionarLinha2: function(){
//encontrar o elemento com id "tblCadastroTBody2" (tbody)
var tbody = document.getElementById('tblCadastroTBody2');
//criar um novo elemento do tipo TR
var tr = document.createElement('tr');
//colocar o conteúdo da linha no TR
tr.innerHTML = cadastro2.linha2;
//inserir a linha criada no tbody
tbody.appendChild(tr);
}
}
</script>