Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda