javascript - Google App Help? Can't make button -


this question has answer here:

i extremely new java script , html , project right make simple calculator, however, cannot button output answer , cannot seem figure out why

my html code is:

    <html>     <head>     <title>calculator</title>     <link rel="stylesheet" href="styles.css">     </head>      <body>      first number:<br>    <input type ="number" id="num1"><br>    second number:<br>   <input type ="number" id="num2"><br>   answer:<br>   <input type= "number" id="answer"><br>   <button id ="add" onclick="add()"> + </button>   <button id ="subtract" onclick="subtract()"> - </button>     <button id ="divide" onclick="divide()"> / </button>       <button id ="multiply" onclick="multiply()"> * </button>        <script src="main.js"></script>     </body>     </html> 

and js code

 var num1 = document.getelementbyid('num1').value;  var num2 = document.getelementbyid('num2').value;  var ans = document.getelementbyid('answer').value;   function add(){    ans = num1 + num2;   document.getelementbyid('answer').value = ans;    }   function subtract(){    ans = num1 - num2;   document.getelementbyid('answer').value = ans;    }   function divide(){    ans = num1 / num2;   document.getelementbyid('answer').value = ans;    }   function multiply(){    ans = num1 * num2;   document.getelementbyid('answer').value = ans;    } 

chrome extension/apps not allow inline definition of event handler (https://developer.chrome.com/extensions/contentsecuritypolicy#jsexecution). use along lines:

document.getelementbyid('add').addeventhandler('click', function() {     ... } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -