简体   繁体   中英

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:

在此处输入图片说明

 <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 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM