The context is some svg code within a web page that draws a mimic diagram (example attached) as the DOM. The mimic diagram is then updated in real time by javascript code. This code is the sub that updates the parts of the heating system pipework where water is actively flowing, as and when the valve configuration changes.
these are the globals:
waterstatic$ = "cornflowerblue"
waterflow$ = "blue"
I'm using globals to make it easy to change the colour scheme as I refine the design.
The version of the sub below works where the blue colours are specified as quoted strings, but not where they are specified as variables:
Code: [Local Link Removed for Guests]
'==========
sub changeflow (page$,targ$,outcome$)
'to ensure that the javascript is only applied when the mimic diagram is displayed as that is where the id is found
'it can be toggled between mimic and a table and generates a (silent) browser error if the id is not found
if ((web_page$ ="table")AND(page$="M"))or((web_page$="mimic")AND(page$="T")) then end sub
'this changes the colour of a pipe line according to whether flow is on or off in the pipe:
if outcome$ = "off" then
'jscall |document.getElementById("|+targ$+|").setAttribute("stroke", "cornflowerblue");| '<- works
jscall |document.getElementById("|+targ$+|").setAttribute("stroke", waterstatic$);| '<- does not work
timestamp "flow "+targ$+" "+outcome$+" "+waterstatic$ '<- but it works here
else
'jscall |document.getElementById("|+targ$+|").setAttribute("stroke", "blue");|
jscall |document.getElementById("|+targ$+|").setAttribute("stroke", waterflow$);|
timestamp "flow "+targ$+" "+outcome$+" "+" "+ waterflow$
endif
end sub
[17/01/24-10:13:58 SRPZhCub:CPbU] displaying web mimic
[17/01/24-10:13:58 SRPZhCub:CPbU] flow boiler_flow on blue '<- correctly reported but not applied
[17/01/24-10:13:58 SRPZhCub:CPbU] flow hw_flow off cornflowerblue
[17/01/24-10:13:58 SRPZhCub:CPbU] flow ch_flow on blue '<- correctly reported but not applied
[17/01/24-10:13:58 SRPZhCub:CPbU] flow ufh_flow off cornflowerblue
[/code]
In the diagram, the left-most blue pipe circuit (c2-c8, r2-r7) which is dark blue remains light blue when the colours are specified as variables.