Just ran on PHP 8.2.23, WP 6.7.1, it worked fine. I just added an example php array, $ReptileID, and it worked fine. Via this code:
<?php
// Simulating a list of fake reptile IDs for testing purposes
$ReptileID = [
'001',
'002',
'003',
'004',
'005',
'006',
'007'
];
?>
<label for="licensetag">Choose A Reptile ID:</label>
<select name="license" id="license">
<?php foreach ($ReptileID as $ReptileID): ?>
<option value="<?php echo $ReptileID; ?>">
<?php echo $ReptileID; ?>
</option>
<?php endforeach; ?>
</select>
<script>
const dropdown = document.getElementById("license");
dropdown.addEventListener("change", function() {
const selectedValue = dropdown.value;
console.log("Selected value:", selectedValue);
<?php echo "selectedValue"; ?>
// Do something with the selected value, e.g., pass it to a function
pullWeights(selectedValue);
});
</script>
Sample outputs: (1) Selected value: 003 (2) Uncaught ReferenceError: pullWeights is not defined. What PHP & WP versions are you using? What else is going on within your file? Can you post your code to a publicly accessible place such as codesandbox or codepen?