Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!