I have the following script by which I want to achieve to dynamically add rows in an HTML table on my website:
<script>
var globalIterationVariable = 0;
document.onload = $globalIterationVariable = 1;
$('document').ready(function() {
$('.add_another').click(function() {
var globalIterationVariable;
var newRowVariable = '<tr><td><center><input name="nazovPolozky';
newRowVariable.append(String($globalIterationVariable));
newRowVariable.append(' type="text"></center></td> <td><center><input name="pocetPolozky');
newRowVariable.append(String($globalIterationVariable));
newRowVariable.append('" type="number" step="1" min="1"></center></td> <td><center><input name="jednotkovaCenaPolozky');
newRowVariable.append(String($globalIterationVariable));
newRowVariable.append('" type="number" step="0.01" min="0.01"></center></td></tr>');
alert(String(newRowVariable));
$("#tbl").append(String(newRowVariable));
globalIterationVariable++
});
});
</script>
This script though gives me the following error:
Uncaught TypeError: newRowVariable.append is not a function
Can anybody, please, help me to get this script working?
Thank you.
P.S.: This script is launched once I press a specific button on my website which has a class='button add_another'
concat
and notappend
asnewRowVariable
is a string and not an HTMLelementglobalIterationVariable++
you are doingundefined++