'php not recognizing string when passing to a js parameter
I am currently working on a webiste and I am using php to connect to the database.
I have a section where I want to have a html <button> tag that changes the src of the same <img> tag. so, i used javascript to make this (this was also from stackoverflow...)
function changeImage(x)
{
var img = document.getElementById("change_image");
img.src=x;
}
</script>
i want to have the parameter x, which is the name of the img (the src part. e.g. flower.jpg). inside the php code, i have a line
echo '<button class="button_a" onclick="changeImage(',$row['photo_a'],');"></button>';
$row['photo_a'] is the file flower.jpg
which is a code to create the button and call the function changeImage
this only gives me the error
ReferenceError: flower is not defined
i believe that this is becuase this is not noticeded as a string, but how can i fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
