Witam serdecznie,
dzisiaj borykam się z czymś, czego nigdy wcześniej nie robiłem - chcę przy każdym "row" aby była możliwość dodania następnego rowa i jego usunięcia. Konsola wywala 78 bledow typu:
Uncaught SyntaxError: Invalid or unexpected token
index.php:548 Uncaught ReferenceError: addMoreRows is not defined
at HTMLAnchorElement.onclick
kod jest mieszany php + jquery i szczerze mówiąc już się zamotałem jak to zrobić, żeby dobrze wyszło, wygląda to tak:
for ($y = 0; $y < $countLinks; $y++)
{
<div class=\"row\" style=\"margin-top: 2px;\" id=\"rowLink".$y."\">
<div class=\"col-sm-8\">
<input class=\"form-control text-center\" type=\"text\" name=\"mainTitle".$x."-linkTitle".$y."\" value=\"".$c -> main[$x] -> link[$y] -> title."\" required /> </div>
<div class=\"col-sm-2\">
<input class=\"form-control text-center\" type=\"text\" name=\"mainPage".$x."-linkPage".$y."\" value=\"".$c -> main[$x] -> link[$y] -> page."\" required /> </div>
<div class=\"col-sm-1\">
<a href=\"java script: void(0);\" class=\"btn btn-md text-center btn-delete\" type=\"button\" style=\"width: 100%;\" onclick=\"removeRow('+rowCount+');\"><span class=\"fa fa-remove icon-md\" title=\"Usuń ten link\"></span></a>
</div>
<div class=\"col-sm-1\">
<a class=\"btn btn-md text-center btn-add\" style=\"width: 100%;\" onclick=\"addMoreRows();\"><span class=\"fa fa-plus icon-md\" title=\"Dodaj link\"></span></a>
</div>
</div>
";
// Skrypt dodający i usuwający link
$z = $y++;
<script>
var rowCount = ".$y.";
function addMoreRows(frm) {
rowCount ++;
var recRow = ' <div class=\"row\" style=\"margin-top: 2px;\" id=\"rowLink'+rowCount+'\">
<div class=\"col-sm-8\">
<input class=\"form-control text-center\" type=\"text\" name=\"mainTitle".$x."-linkTitle".$z."\" required />
</div>
<div class=\"col-sm-2\">
<input class=\"form-control text-center\" type=\"text\" name=\"mainPage".$x."-linkPage".$z."\" required />
</div>
<div class=\"col-sm-1\">
<a href=\"java script: void(0);\" onclick=\"removeRow('+rowCount+');\">Delete</a>
</div>
</div>';
$('#rowLink".$y."').append(recRow);
}
function removeRow(removeNum) {
$('#rowLink".$z."' + removeNum).remove();
}
</script>
";
}