310
Views
7
Comments
Run Javascript at start

Hi,

In mobile application, I want to set div HTML using javascript at beginning. I have tried screen onready and onrender events to run javascript. I am getting error - Cannot set property 'innerHTML' of null

Where should I run javascript to place HTML dynamically?


Best Regards,

Nitin Chavan

2021-01-12 13-21-28
Kadu Borges

Hi Nitin Chavan,

The best place to do it is on the OnReady event, because it is when the DOM is complete. As you already tried this, I have to ask you where is this DivNav element? Are you sore that this is its ID on the rendered screen?

Have you inspect the element through the browser?

OutSystems changed the names of the components when building the page, so you cannot rely on widget names. I have made a test and It works fine. Please, refer to the oml file attached. 

Hope it helps

Best regards


PhoneOnready.oml
2022-08-26 11-04-22
Nitin Chavan

Hi @Kadu Borges ,

I have inspected DOM and its showing HTML with id.

Now I am passing ID in JS parameters, still giving error -

Best Regards,

Nitin

2021-01-12 13-21-28
Kadu Borges

Is the this HTML element inside a Web Block?

2022-08-26 11-04-22
Nitin Chavan

Yes directly inside mobile screen. 

I have used class name too. Still it's not working-

var x = document.getElementsByClassName("j-DivNav");

x[0].innerHTML= $parameters.paramtxt;

2021-01-12 13-21-28
Kadu Borges

Could you share your oml file?

2022-08-26 11-04-22
Nitin Chavan

Hi @Kadu Borges ,

Got the problem. 'If' condition is creating problem. When I place container outside 'if' it's working fine.


2021-01-12 13-21-28
Kadu Borges

Well done. This kind of problem is a nightmare to understand.

Best regards.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.