I’ve been working on a piece of dynamic JavaScript code:
$(document).ready(function() {
<?php
$sql = "SELECT * from pm_schedule";
$result = $pdo->query($sql);
foreach ($result as $row)
{
echo
"$('#updatebtn".$row['id']."').click(function() {
$('#result".$row['id']."').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform".$row['id']."').serialize(),
});";
}
?>
});
It expands to the following when I run it on my server:
$(document).ready(function () {
$('#updatebtn1').click(function () {
$('#result1').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform1').serialize(),
});
$('#updatebtn2').click(function () {
$('#result2').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform2').serialize(),
});
$('#updatebtn3').click(function () {
$('#result3').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform3').serialize(),
});
$('#updatebtn4').click(function () {
$('#result4').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform4').serialize(),
});
$('#updatebtn5').click(function () {
$('#result5').show('slow').delay(4000).hide('slow')
$.post('process.php', $('#updateform5').serialize(),
});
});
Google Chrome keeps returning an uncaught syntax error for the code above – any idea as to why? Please note that I have to make edits to the first code block and not the second.
Replace the comma
,at the end here$('#updateform".$row['id']."').serialize(),<– with a)