B4J Question [jServer] setHTML with js element

Blueforcer

Active Member
Licensed User
Hello,

i want to place a spinner on my side wich needs a javascript to run.
This javascript call is right before the body ends
<script src="../plugins/jquery-spinner/js/jquery.spinner.js"></script>

The Spinner works fine if i place it hardcoded in the HTML file,
but if i use setHTML with a websocket to place the exact same code into a div, the spinner doesnt work anymore.

What i have to do?
 

Blueforcer

Active Member
Licensed User
Thank you this works in that case. But not always.
For example:

I have some elements (e.g a dropdown) inside a div with ID "content" pushed by setHTML.

as soon as i have the sub content_Click (Params As Map) the elements doesnt work anymore.

even if i load every js with getScript again

it looks like the b4j event replaces or overwrite the event to show the dropdownmenu or something like that
 
Last edited:

OliverA

Expert
Licensed User
I have some elements (e.g a dropdown) inside a div with ID "content" pushed by setHTML.
Since you have to declare this statically in you B4J code (via a something like: Dim content As JQueryElement), why don't you just also put it statically in you HTML and use the display property to show/hide the element as needed?
B4X:
'To hide the div with id content
content.SetProp("display", "none")
'To show the div
content.SetProp("display", "block")
You could also use the visbility property
Links:
https://www.w3schools.com/cssref/pr_class_display.asp
https://www.w3schools.com/cssref/pr_class_visibility.asp
 

Blueforcer

Active Member
Licensed User
i have declare it.
The content needs to be dynamic because its an appstore and will build according apps in a online Database.
So its not possible to hardcode each element.

But since i need to catch every button click inside each "App"-Element I need to do it by the whole content click event and select the click by the target.
 

OliverA

Expert
Licensed User
You can create a callback via ws.Eval and JavaScript. For example, an elements click event can be set via
B4X:
Dim elementID As String = "content"
Dim clickJS As String = $"   $("#${elementID}").on("click",function(){
                         b4j_raiseEvent('${elementID}_click', {'callerID' : '${elementID}'});
                      });"$
ws.Eval(clickJS, Null)
then
B4X:
Sub content_click (Params As Map)
   Log(Params)
End Sub
should log an callerID map entry.
Notes:
1) Untested code
2) You've placed an element with ID "content" via setHTML
3) The HTML element with ID "content" needs to have a click event for this to work
 
Top