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