Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/JavaScript">
- function get(eid) {return document.getElementById(eid);};
- function calculate(op){
- var a = parseFloat(get('a').value);
- var b = parseFloat(get('b').value);
- if (isNaN(a) || isNaN(b)) {
- alert('both inputs must be numbers');
- return;
- }
- var answer = a + op + b + ' = ' + eval('a' + op + 'b');
- get('resultAsTextBox').value = answer;
- }
- </script>
- </head>
- <body>
- <form>
- <p>
- Instructions:<br />
- Type two numbers and click a button.<br />
- The answer will then appear below.<br /><br />
- Input values:<br/ >
- First number to include: = <input id="a" type="text" /><br />
- Second number to include: = <input id="b" type="text" /><br /><br />
- <input type="button" value=" + " onclick="calculate(this.value)" />
- <input type="button" value=" - " onclick="calculate(this.value )" />
- <input type="button" value=" * " onclick="calculate(this.value)" />
- <input type="button" value=" / " onclick="calculate(this.value)" /><br />
- Output value:<br />
- Result= <input type="text" id="resultAsTextBox" size="50" disabled="disabled" />
- <p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement