How to get a javascript value?

I have a web app and I’m having problems getting a value from a javascript function in the HTMLHeader.

I’m calling the function using ExecuteJavaScript, but I can’t seem to find out how to get the returned value.

Is there a way to get a value from a javascript function?

The easiest way would be to put the return value into a hidden textfield on your page. Otherwise you could create a custom control using the WebSDK that would allow you to send the data back.

Thanks Greg.

How would I set the hidden xojo textfield from JavaScript?

I tried this: ExecuteJavaScript(" xojo.controls[’" + MessageAttachment.ControlID + "’].setValue(‘hello there’); ")

But I got this error when I clicked the button:

I also tried: SetTextByControlID ( MessageAttachment.ControlID, “hello world” )

Which called the method:

[code]SetTextByControlID ( controlID as string, text as string )
dim js as string

js=“document.getElementById(’”+controlID+"_inner’).value=’"+text+"’;"

self.ExecuteJavaScript(js)[/code]

That displayed the value in the field, but when I ran

MsgBox MessageAttachment.Text

It didn’t show “hello world”, but rather an empty msgbox.

Just tried the same thing as Hal. It appears that the text value is not changed until after the msgbox is called. Is that true?

Is there another way to get a value from javascript back into xojo?

Not only after the MsgBox has been called, but after the Xojo method has ended. You can have a dozen of ExecuteJavaScript calls in a method, they are all run after the method has ended.

Unfortunately not synchronously.

As I’ve said in other threads, everything you do with JavaScript is asynchronous. Any commands that you send via ExecuteJavascript are sent after your method ends, so in this case the command to display the msgbox is created (including the old value) and then all of the commands are sent to the browser. Your JavaScript does run, but it’s way too late.

[quote=277661:@John Scanlan]Just tried the same thing as Hal. It appears that the text value is not changed until after the msgbox is called. Is that true?

Is there another way to get a value from javascript back into xojo?[/quote]

Yes, TriggerServerEvent, in WebSDK. See WebSDK.pdf, in the Extras/WebSDK folder next to your Xojo copy.

Ok … My issue can be fully resolved by provided drag and drop between weblistboxes or at least having rowheight provide the computed rowheight as opposed to the minimum rowheight.