anonymous9
01-20-2012, 03:44 PM
How can I ask the user for two different numbers and add them?
|
||||
How take an input and add itanonymous9 01-20-2012, 03:44 PM How can I ask the user for two different numbers and add them? Philip M 01-20-2012, 04:09 PM This is a pretty basic homework question which you should really answer using a Javascript textbook. But First Number <input type = "text" id = "first"><br> Second Number <input type = "text" id = "second"><br> <input type = "button" value = "Add 'em up" onclick = "add()"><br> Total <input type = text" id = "total" readonly> <script type = "text/javascript"> function add() { var a = document.getElementById("first").value; var b = document.getElementById("second").value; var t = Number(a) + Number (b); // convert from strings to numbers document.getElementById("total").value = t; } </script> “He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him.” |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum