I am currently working on a project involving multiple languages including HTML/JS/PHP.
In one of my PHP functions, I discovered an unexpected behavior.
I broke it down to simpler functions so it would be clearer :
<?php
function generateInput($inputID, $oninputFunction)
{
echo '<input id="' . $inputID . '" oninput="' . $oninputFunction . '">';
}
function generateDIV(){
$ID = "someId";
echo '<div>';
generateInput($ID, 'someFunction('. $ID .')');
echo '</div>';
}
?>
<script>
function someFunction(selectID) {
console.log(selectID);
}
</script>
<!DOCTYPE html>
<html>
<body>
<?php generateDIV() ?>
</body>
</html>
As you can tell, the expected console output when something is typed in the input is "someId". However, for some reason, the output is the HTML element which is:
<input id="someId" oninput="someFunction(someId)">
If anyone has an explanation to this behavior, please let me know.