Ad
Function Is Undefined, But I Had Defined It
I'm a PLC programmer, i made a html page and i need it script refresh every second, so in my body i placed:
<body onload="changeimage()">
.... code ....
</body>
And the script:
<script>
setInterval(function changeimage() {
var sonde = ["Sonda1","Sonda2","Sonda3","Sonda4"];
var tsonde = ["tsonda1","tsonda2","tsonda3","tsonda4"];
var temperature = [:="OUTPUT".AlarmTemp.Sonda1:,:="OUTPUT".AlarmTemp.Sonda2:,:="OUTPUT".AlarmTemp.Sonda3:,:="OUTPUT".AlarmTemp.Sonda4:];
var hotcold = document.getElementById("Fiocco");
if (:="OUTPUT".Stagione.Estate: > 0){
hotcold.src="sun.jpg"}
if (:="OUTPUT".Stagione.Inverno: > 0){
hotcold.src="Neve.png"}
for (x in temperature) {
var icona = document.getElementById(sonde[x]);
if (temperature[x] > 0 ){
icona.src="Paverde.png"
}
else{
icona.src="Parossa.png"
}
}
}, 1000);
</script>
Anyway i get the error: ReferenceError: changeimage is not defined
P.S.: Don't get fooled by the arrays who start with ":", is a PLC syntax, is correct.
@ Even removing the setinterval option, the script is not working.
Ad
Answer
Define the function first and make sure the script is loaded.
Example in code pen: https://codepen.io/mikila85/pen/NWPvQPE
function changeimage() {
setInterval(function() {
var sonde = ["Sonda1","Sonda2","Sonda3","Sonda4"];
var tsonde = ["tsonda1","tsonda2","tsonda3","tsonda4"];
var temperature = [:="OUTPUT".AlarmTemp.Sonda1:,:="OUTPUT".AlarmTemp.Sonda2:,:="OUTPUT".AlarmTemp.Sonda3:,:="OUTPUT".AlarmTemp.Sonda4:];
var hotcold = document.getElementById("Fiocco");
if (:="OUTPUT".Stagione.Estate: > 0){
hotcold.src="sun.jpg"
}
if (:="OUTPUT".Stagione.Inverno: > 0){
hotcold.src="Neve.png"
}
for (x in temperature) {
var icona = document.getElementById(sonde[x]);
if (temperature[x] > 0 ){
icona.src="Paverde.png"
}
else{
icona.src="Parossa.png"
}
}
}, 1000);
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad