Logic Machine Forum
Change Background Image On Object Value - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Change Background Image On Object Value (/showthread.php?tid=2253)



Change Background Image On Object Value - manos@dynamitec - 25.09.2019

Hello All,

Is there a way to change the background image of an image element via object value? 
Or can I have 4 sets of elements including images, buttons, value dispaly on the same page and change the visibility of them based on a virtual object 250byte value?

Value 1 = Make visible set 1 and hide all the other sets
Value 2 = Make visible set 2 and hide all the other sets
Value 3 = Make visible set 3 and hide all the other sets
Value 4 = Make visible set 4 and hide all the other sets


Thank you in advance


RE: Change Background Image On Object Value - Daniel - 25.09.2019

have you seen this? https://forum.logicmachine.net/showthread.php?tid=275&pid=2205#pid2205


RE: Change Background Image On Object Value - manos@dynamitec - 26.09.2019

Hello Daniel.

I have done this and works but if I refresh the page the background image is lost. Is there a solution to this?

Code:
$(function(){
  if (typeof grp != 'undefined') {
    grp.listen('32/1/4', function(object, state) {
      var image = $('.hvac_image')[0]
      if (state == 'value') {
        if (object.value == 1) {image.innerHTML = '<img src="scada/resources/img/HVACFlowDiagram1.PNG?1569506491">';}
        else if (object.value == 2) {image.innerHTML = '<img src="scada/resources/img/HVACFlowDiagram2.PNG?1569506498">';}
        else if (object.value == 3) {image.innerHTML = '<img src="scada/resources/img/HVACFlowDiagram3.PNG?1569506503">';}
        else if (object.value == 4) {image.innerHTML = '<img src="scada/resources/img/HVACFlowDiagram4.PNG?1569506509">';}
        }
    });
  }
});


Thanks for your help.


RE: Change Background Image On Object Value - Erwin van der Zwart - 26.09.2019

Hi,

Currently your script is executed on state "value", this means that during init the script is not executed as state is "init" in that case, you could remove the "if (state == 'value') { ... }" condition to have it also executed on init so it is directly triggered after a refresh. Or you can add a extra condition like "if (state == 'init') { ... }"

BR,

Erwin