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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -