In my project some php codes need to be inside the javascript codes. I typed following codes. But its wrong and i am not skilled on javascript. Can you help me to edit this code. Error is around the $rowno
variable. $rowno
is undefined in php code whereas $rowno
is ok in first line in var html
of javascript. How i can defined $rowno
for php...
<script type="text/javascript">
$(document).ready(function (e) {
$("#add").click(function (e) {
$rowno = $("#container div.sss").length;
$rowno = $rowno + 1;
var html = "<div class='sss' id='row" + $rowno + "'>This Form</div><div class='col-sm-12'><?php include_once 'db.php'; $sql = mysqli_query($connection, 'SELECT * FROM service'); while ($row = $sql->fetch_assoc()) {
echo "<label><input name='checkbox["$rowno"][]' value='$row[id]' type='checkbox'>$row[title]</label>";
} ?></div></div>";
$("#container").append(html);
});
});
</script>