Xojo and Javascript

I have no experience with Javascript I try to explain to my students how to access information on a webpage from a Xojo desktop app.

I have an input field on a webpage referenced with id = mt_organizationno". The page is open and available with HTMLViever1 (Class DesktopHTMLViewer). How can I get the information from the input field? This was my guess:

Var titlePage As String  = htmlviewer1.ExecuteJavaScriptSync("document.title")

Var organisationNumber As String htmlviewer1.ExecuteJavaScriptSync("document.GetElementById(""mt_organizationno"").Value")

The title is displayed correctly. However, the variable organisationNumber is empty. Is there an error in the Javascript sentence?

do not mix upper lower case names. Methods are camelCase

if you open/view this in firefox browser, see console output.


<input type='text' id='a' value='Hello'>
function test() {
 var element=document.getElementById('a');

I changed getElementById in Camel case but the result is still empty. Yes, your javascript program works well. Is it necessary to put the Javascript function in a separate string?

have you changed it to lower case too?


Thank you, now it’s perfect!

Var organisationNumber As String = htmlviewer1.ExecuteJavaScriptSync("document.getElementById(""mt_organizationno"").value;")
1 Like