I'm creating a select in javascript and I'm using this statement to fill the options with the data in the database, but I do not load the data in the option and nor the select when I enter the page, What am I doing wrong?
var option1 = document.createElement("select");
option1.setAttribute("name","select1");
option1.setAttribute("id","select1"+largo);
option1.className ="select";
var miOption1=document.createElement("option");
<?php
$stmt=user($conn);
$arr = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($arr as $row) {
miOption1.setAttribute("value",".$row['us_id'].");
miOption1.setAttribute("label",".$row['us_nom'].");
}
?>
option1.appendChild(miOption1);