2
I just want to add up the values I get on input
, what’s wrong with the code?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function calcula(){
var soma = document.getElementsById('valor').value;
var total =0;
total+= soma;
document.getElementById("resultado").innerHTML = total;
}
</script>
</head>
<body>
<input type="text" name="valor">
<button id="calc" onclick="calcula()">Soma</button>
<h3 id="resultado"></h3>
</body>
</html>
This method is unique:
getElementById
– Sergio
If you have a new question, ask it in [Ask]. Do not edit the current question so that it can invalidate the answers given. Each problem, a separate question. What you can do to finalize the question is to mark the answer as accepted. See how in [tour]. After that you will also have the right to vote on everything you find useful on the site.
– Maniero
Did the answer solve your problem? Do you think you can accept it? If you don’t know how you do it, check out [tour]. This would help a lot to indicate that the solution was useful to you and to give an indication that there was a satisfactory solution. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero