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

212
Views
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 answers
Answer question

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 Report
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!