Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda