I'm trying to create a button within a table that passes its particular field data into a javascript function upon it being clicked, however when I press the 2nd button I get a "Uncaught syntax error: missing ) after argument list", can anyone see anything wrong with the code?
echo '<tr>
<td scope="row">' . $row["Type"]. '</td>
<td><img src='.$row['Image'].' height="100" width="100"></td>
<td> '.$row["Price"] .'</td>
<td><button type="button" class="btn btn-primary" id = "buybtn" onclick="foodChosen('.$row["Type"].','.$row["Price"].')">Buy</button></td>
</tr>';
}
Drop out of PHP before outputting that block of code and use a consistent quoting style.
?>
<tr>
<td scope="row"><?php echo $row['Type']; ?></td>
<td><img src="<?php echo $row['Image']; ?>" height="100" width="100"></td>
<td><?php echo $row['Price']; ?></td>
<td><button type="button" class="btn btn-primary" id="buybtn" onclick="foodChosen('<?php echo $row['Type'] . ',' . $row["Price"]; ?>')">Buy</button></td>
</tr>