JavaScript response from DOM


I’m struggling with JavaScript and the WebSDK.

I’ve made a control, where I set some HTML-Stuff in the ‘HTMLSetup’-Event and use a computed property do change the HTML with JavaScript like

ExecuteJavaScript("tinymce.get('area1').setContent('" + value + "');")

But now I want to get a value back.

The DOM looks like this:


Lars is the coolest

[/code] Now thought to use JavaScript to get the innerHTML of "tinymce" back. The Documentation and dhe Docs says I should use:

Dim s As String s = "document.getElementById('tinymce').innerHTML;" WebPage1.area.ExecuteJavaScript(s)

But where I can handle the result???

Stupid question, maybe, but please help me!

Everything on the web is asynchronous. What you’ll need to do is use the Xojo.TriggerServerEvent javascript method to have the page send the value back to the server.

Okay, I’m able to call an Event with Xojo.TriggerServerEvent

s = s + "Xojo.comm.triggerEvent('" + self.controlID + "','HTMLChanged');" self.ExecuteJavaScript(s)

but how can I hand over a value? I want to send the value of this function back to the app:



To Raise the Event I use the ‘ExecuteEvent’-event with this code:

[code] Select Case name

Case “HTMLChanged”
mHTML = parameters(0)
RaiseEvent HTMLChanged
Catch err As OutOfBoundsException

End Try

End Select
Return True[/code]

But where can handle the paramters(0) ???

Whohoo, I solved my problem
A short look in the Xojo-JS-Framework gave me the answer.
I just had to overgive an array in the Xojo-Event - that’s simple!

 s = s + "Xojo.comm.triggerEvent('" + self.controlID + "','GetContent', [tinymce.get('area1').getContent()])"

Don’t use the .comm version. That’s an internal call and may change in the future. The one I gave you is part of the documented SDK.

The third parameter (after the event name) is an array of parameters.

Lars, please look at the WebSDK docs which are in the Extras folder next to the IDE. it explains the methods you may use for your own controls without risking calling internal methods.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.