0
Dear, hello.
I need to do some calculations using input type="range", but I am not able to run the code on my machine, only in online editors and I would like to know why this occurs? I use windows 10 and the text editor is the Notepad++.
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<script>
function generateResult() {
var range1 = parseInt(document.getElementById('range1').value);
var range2 = parseInt(document.getElementById('range2').value);
document.getElementById('result').innerHTML = range1 + range2;
}
document.getElementById('range1').addEventListener('change', function(){
generateResult();
});
document.getElementById('range2').addEventListener('change', function(){
generateResult();
});
</script>
<div>
Range
<input type="range" class="observe" id="range1">
<input type="range" class="observe" id="range2">
</div>
<div>
Resultado
<div id="result"></div>
</div>
</body>
</html>
Hello Marck can explain better "do some calculations" and what do you mean by "I’m not getting the code running"? which error, expected result, etc?
– Ricardo Pontual
Hello, referring to the calculation would be add, divide and etc.
– Marck
You have to know exactly what you want to do, give concrete examples of the various calculations you want to do and where they would enter the page. As a note, do not
+range1.value
to convert to whole unless you are in a codegolf competition.– Isac
Come on, the question of "calculations" I have already managed to do, which is to add the two inputs, but I’m not able to run them unless by online editors like the one available by stackoverflow
– Marck
Another error I found: In the result.innerHTML line, unless you have assigned some value to some variable called result, it must present some error. Should be
document.getElementById('result').innerHTML = //atribuição
– Máttheus Spoo
So the code works on Jsfiddle but not local
– Marck
I believe that if you focus on solving syntax errors and worry less about where it works and where it doesn’t work you’ll get the answer sooner.
– Máttheus Spoo
I made the changes you had informed but still not working
– Marck
I’m making a code to put in the answer and then you can see where you missed, wait a moment
– Máttheus Spoo
Okay, thank you very much
– Marck