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

213
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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