B4J Question Send and receive boolean value (web server)

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
How to send a boolean variable (with web server) and in index.htlm work with it?
In practice by the server sending a variable
and based on the value of this, I make visible or hide an image.
Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
Ok but in my case it is necessary to modify index.html
In my application I send a string (in you example is the time) and I would also send the boolean value to show or hide an image.
In index.html:
<img border="0" src="image.png" id="IMGS" style="visibility:hidden"/>
...........
how i can capture the boolean value and manage the image display?
Thanks
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Tanks Erel but I can not create a working code.

Into WebSocket code:

Class Global
Private temperature, up as JQueryElement
..........

Sub Timer1_Tick
.........
temperature.SetHtml(t)
If Main.upimg.Visible Then up.SetVal(True) Else up.SetVal(False)
........

Into Index.html
........
<div ><p id="temperature"></p></div>
<var id="up"></var)
<img border="0" src="upimg.png" id="IMGS" style="visibility:hidden"/>
.......
<script>
//connect to the web socket when the page is ready.
$( document ).ready(function() {
b4j_connect("/ws");
});
if ("up")
{
document.getElementById('IMGS').style.visibility='visible';
}
else
{
document.getElementById('IMGS').style.display='hidden';
}
</script>

where is the error?
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
try

B4X:
'change IMGS to imgs, and dim imgs as JQueryElement ,id should in lower-case for b4j; 
<img border="0" src="upimg.png" id="imgs" style="display:none"/>

Private imgs as JQueryElement


Sub Timer1_Tick
.........
temperature.SetHtml(t)
If Main.upimg.Visible Then
  imgs.SetCSS("display", "none")
Else
  imgs.SetCSS("display", "block")
End If
........
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Thanks billzhan and Erel
the image are in www, then in index.css how I define the image?
Sorry but I'm not practical to html and css

for my use better to use the parameter visible and not display
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
no need to change index.css
B4X:
'html:
'img: www/upimg.png
<img border="0" src="/upimg.png" id="imgs" style="display:none"/>

'img: in the same folder of the html file
->  src="upimg.png"
 
Upvote 0
Top