uncaught referenceerror calculate is not defined at HTMLInputElement.onChange

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



uncaught referenceerror calculate is not defined at HTMLInputElement.onChange



The error I am getting is in the title. (uncaught referenceerror calculate is not defined at HTMLInputElement.onChange) This works if I run it along from notepad++, but when I run it within the website, I get that error. Would anyone be able to shed some light on this? Any help is appreciated.




<p style="text-align: center;"><strong>CBD %</strong></p>
<input id="box1" type="number" value="5" onchange="calculate()"/>
<p style="text-align: center;"><strong>Bottle size (ml)</strong></p>
<input id="box2" type="number" value="100" onchange="calculate()"/>
<p style="text-align: center;"><strong>Calculated value</strong></p>
<input id="result" type="number" value="500" />

<script>
function calculate()

var myBox1 = document.getElementById('box1').value;
var myBox2 = document.getElementById('box2').value;
var result = document.getElementById('result');
var myResult = myBox1 * myBox2;

document.getElementById('result').value = myResult;


</script>



Screenshot of console:



enter image description here





Looks like it has little to do with the code you've shared here, but rather something else, considering the other errors displayed in your console.
– Heretic Monkey
Aug 8 at 18:19




1 Answer
1




<script>
function calculate()

var myBox1 = document.getElementById('box1').value;
var myBox2 = document.getElementById('box2').value;
var result = document.getElementById('result');
var myResult = myBox1 * myBox2;

document.getElementById('result').value = myResult;


} //<---- unwanted character
</script>


<p style="text-align: center;"><strong>CBD %</strong></p>
<input id="box1" type="number" value="5" onchange="calculate()"/>
<p style="text-align: center;"><strong>Bottle size (ml)</strong></p>
<input id="box2" type="number" value="100" onchange="calculate()"/>
<p style="text-align: center;"><strong>Calculated value</strong></p>
<input id="result" type="number" value="500" />



see if an unwanted character is in the script it cause that error. maybe check that enter image description here





Just tried that, but still getting the issue
– Jack Bracey
Aug 8 at 17:55





I'll add a screenshot of the console errors
– Jack Bracey
Aug 8 at 17:55





yes that could help
– Hiroshi Kitagawa Hirowa
Aug 8 at 17:57





if thats just a snippet of the entire code then the problem might be on the other part of the html that snippet is in.
– Hiroshi Kitagawa Hirowa
Aug 8 at 18:00





There's a link at the bottom of the post now
– Jack Bracey
Aug 8 at 18:00






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard