Reporting JavaScript BUG - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, June 16, 2023

Reporting JavaScript BUG

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.



source https://stackoverflow.com/questions/76484329/reporting-javascript-bug

No comments:

Post a Comment