forms - HTML calculator , + doesnt works -
i made calculator, +
doesn't work, why?? -> if want + something, have press button : sečíst .... doesn't + it, writes in bad way, take : http://jsfiddle.net/p77roqhr/
<pre> <!doctype html> <html lang="cs-cz"> <head> <meta charset="utf-8"> <meta name="generator" content="prace"> <link rel="stylesheet" href="online_kalkulacka.css"> <title>kalkulačka</title> </head> <body> <h1>kalkulačka</h1> <form name="kalkulacka"> <fieldset> <div id="cislo1"> <label for="vypln_cislo1">zadej zde první číslo</label> <input id="1" type="number" name="prvni" min="0" max="10000"> </div> <div id="cislo2"> <label for="vypln_cislo2">zadej zde druhé číslo</label> <input id="2" type="number" name="druhe" min="0" max="10000"> </div> <button id="b1" onclick="document.getelementbyid('3').innertext = document.getelementbyid('1').value + document.getelementbyid('2').value; homecoming false;">sečíst</button> <button id="b2" onclick="document.getelementbyid('3').innertext = document.getelementbyid('1').value - document.getelementbyid('2').value; homecoming false;">odečíst</button> <button id="b3" onclick="document.getelementbyid('3').innertext = document.getelementbyid('1').value / document.getelementbyid('2').value; homecoming false;">vydělit</button> <button id="b4" onclick="document.getelementbyid('3').innertext = document.getelementbyid('1').value * document.getelementbyid('2').value; homecoming false;">vynásobit</button> <div id="vysledek"> výsledek je : <br> <div id="vysledek2"> <span id="3"></span> </div> </div> </fieldset> </form> </body> </html> </pre>
you have convert each number first add together them number instead of doing string concatenation. parseint()
.
change code
<button id="b1" onclick="document.getelementbyid('3').innertext = parseint(document.getelementbyid('1').value, 10) + parseint(document.getelementbyid('2').value, 10); homecoming false;">sečíst</button>
html forms button label fieldset
No comments:
Post a Comment