html - How to run a JavaScript function on an input field when a button is pressed -
this question has answer here:
i'm trying remember how associate html , js through different actions, wrote simple reverse script (any number turned string , reversed)
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> </head> <body> <h1>number reverser</h1> <script> function reverser(n){ n = n + ""; return n.split("").reverse().join(""); } function executerev(){ console.log(reverser()); } </script> <input id="bubu"> <button onclick="executerev()">reverse 'em</button> </body> </html>
the ridiculous part console returned
denifednu
my genius js level managed reverse error itself.
how can connect input function executed on button press , displayed in div (any div, not console)?
i'm not entirely sure mean think might talking using dom. instance, update div id="x", following.
document.getelementbyid("x").innerhtml = "new content";
Comments
Post a Comment