0

How do I go about this? I want to use a HTML form to obtain two inputs (both integers) from the user. and then use JavaScript to alert the sum (or print it on the page) when the user clicks an 'Ok' button.. A simple sample code will be appreciated. thank you.

Forms and JavaScript

11th Jan 2017, 12:46 PM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar
4 Réponses
+ 5
HTML : <input type=number> <input type=number> <button onclick="sum()">Button</button> JS : function sum() { alert(document.getElementsByTagName("input")[0].value * 1 + document.getElementsByTagName("input")[1].value * 1) }
11th Jan 2017, 1:02 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
0
thanks
11th Jan 2017, 7:45 PM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar
0
интересно
12th Jan 2017, 10:18 AM
Сергей Зязев
Сергей Зязев - avatar
0
what if I want to use innerHTML property to print d result on the page
12th Jan 2017, 7:25 PM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar