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

214
Visualizações
is there an method to send multiple PHP variables to custom JavaScript function as an parameter in external file of type module?

I am working with three.js and WebGL. I am currently trying to send references from the database to a custom javascript function to load a model but I am getting results undefined in the alert. I am using a JavaScript file as a type module.

<script type="module" src="./script.js"></script>

here is my PHP & HTML code.

<div class="model-options">
   <?php
      $q_read=mysqli_query($dbc, "SELECT * FROM model");  
      while($row=mysqli_fetch_array($q_read))
      {
         echo "<div class='model1-img models'>";
         echo "<img src='".$row['model_img']."' onclick='load1model(".$row['model_link'].")'>";
         echo "</div>";
      }
   ?>
</div>

And here is my JavaScript code.

function load1model(model_value) {
   alert(model_value);
};

If you want to know something else then let me know.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The parameter to load1model() isn't being quoted in the generated HTML. Try adding escaped double quotation marks to the relevant line in the PHP, like so (note the \"'s).

echo "<img src='".$row['model_img']."' onclick='load1model(\"".$row['model_link']."\")'>";

After that change, the onclick handler should read as onclick='load1model("ASSETS/models/car-1.gltf")' (note the double quotes around ASSETS...gltf; these are needed to identify that as a string in the generated JavaScript.

about 4 years ago · Santiago Gelvez Relatório
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