javascript - How to output a reverse string using innerHTML? -


i'm trying reverse string , output results using innerhtml. nothing output when click button.

    <input type="text" id="text">     <button id="reversal">reverse</button>     <div id="results"></div>  <script type="text/javascript">      var input1 = document.getelementbyid("text").value;     var button = document.getelementbyid("reversal");     var result = document.getelementbyid("results");      var reversals = function(string) {         result.innerhtml = string.split("").reverse().join("");     }      button.onlclick = function() {         reversals(input1);     } </script> 

this should do.

input1 = document.getelementbyid("text").value; should assigned within onclick handler.

var button = document.getelementbyid("reversal"); var result = document.getelementbyid("results");  var reversals = function(string) {     result.innerhtml = string.split("").reverse().join(""); }  button.onclick = function() {     var input1 = document.getelementbyid("text").value;     reversals(input1); } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -