560
Views
8
Comments
Solved
When using WebBlock, i want to use javascript to hide a div(container)
Question

When using WebBlock, i want to use javascript to hide a div(container), but im getting undefined funtion call and i dont get it why dont work

2020-03-01 17-52-33
Nikhil Gaur
Solution

Marcio Carvalho wrote:

Nikhil Gaur wrote:

Hi Marcio,

I think you are using getElementById javascript method to get the container and then setting its style. So while using getElementById keep in mind that you have to use dynamically generated id of the contiiner not the name you entered in service studio for the container.

So you have to do something like this when adding your script in expression:

SyntaxEditor Code Snippet

"<script>var x = document.getElementById("+ContainerName.Id+");
  if (x.style.display === ""none"") {
    x.style.display = ""block"";
  } else {
    x.style.display = ""none"";
  }</script>"

Note the parameter in getElementById. You have to use your container name and use its Id property to concatinate in script.

Yes thats It, im trying with id, but im newbie and i dont know how OS works with javascript, i already saw problems like this, and all of them was doing with nodejavscript, or run javscript action. I dont know how to do it in the simpliest way


Hi Marcio,

If you are doing it in treditional web app then you have to add an expression in the screen and set its excape content property to No. In this expression just add this script as string and it will work like what you want. Just make sure that this expression should come after the container in your screen.

If you are using reactive web app then you can add an oninitialize event on screen and add this script using a js block in the event.

I would also recoment you to complete your web application development training first where you will find answers to most of the queries like this.

https://www.outsystems.com/learn/paths/2/becoming-a-traditional-web-developer/

https://www.outsystems.com/learn/paths/18/becoming-a-reactive-web-developer/

2018-12-09 19-13-19
Tiago Gomes

Hello Marcio,

Why dont you use for example, some if or "display:none" to hide it? Needs to be with javascript?

Regards

2020-03-01 17-52-33
Nikhil Gaur

Hi Marcio,

I think you are using getElementById javascript method to get the container and then setting its style. So while using getElementById keep in mind that you have to use dynamically generated id of the contiiner not the name you entered in service studio for the container.

So you have to do something like this when adding your script in expression:

SyntaxEditor Code Snippet

"<script>var x = document.getElementById("+ContainerName.Id+");
  if (x.style.display === ""none"") {
    x.style.display = ""block"";
  } else {
    x.style.display = ""none"";
  }</script>"

Note the parameter in getElementById. You have to use your container name and use its Id property to concatinate in script.

2021-06-02 20-50-04
Márcio Carvalho

Nikhil Gaur wrote:

Hi Marcio,

I think you are using getElementById javascript method to get the container and then setting its style. So while using getElementById keep in mind that you have to use dynamically generated id of the contiiner not the name you entered in service studio for the container.

So you have to do something like this when adding your script in expression:

SyntaxEditor Code Snippet

"<script>var x = document.getElementById("+ContainerName.Id+");
  if (x.style.display === ""none"") {
    x.style.display = ""block"";
  } else {
    x.style.display = ""none"";
  }</script>"

Note the parameter in getElementById. You have to use your container name and use its Id property to concatinate in script.

Yes thats It, im trying with id, but im newbie and i dont know how OS works with javascript, i already saw problems like this, and all of them was doing with nodejavscript, or run javscript action. I dont know how to do it in the simpliest way


2020-03-01 17-52-33
Nikhil Gaur
Solution

Marcio Carvalho wrote:

Nikhil Gaur wrote:

Hi Marcio,

I think you are using getElementById javascript method to get the container and then setting its style. So while using getElementById keep in mind that you have to use dynamically generated id of the contiiner not the name you entered in service studio for the container.

So you have to do something like this when adding your script in expression:

SyntaxEditor Code Snippet

"<script>var x = document.getElementById("+ContainerName.Id+");
  if (x.style.display === ""none"") {
    x.style.display = ""block"";
  } else {
    x.style.display = ""none"";
  }</script>"

Note the parameter in getElementById. You have to use your container name and use its Id property to concatinate in script.

Yes thats It, im trying with id, but im newbie and i dont know how OS works with javascript, i already saw problems like this, and all of them was doing with nodejavscript, or run javscript action. I dont know how to do it in the simpliest way


Hi Marcio,

If you are doing it in treditional web app then you have to add an expression in the screen and set its excape content property to No. In this expression just add this script as string and it will work like what you want. Just make sure that this expression should come after the container in your screen.

If you are using reactive web app then you can add an oninitialize event on screen and add this script using a js block in the event.

I would also recoment you to complete your web application development training first where you will find answers to most of the queries like this.

https://www.outsystems.com/learn/paths/2/becoming-a-traditional-web-developer/

https://www.outsystems.com/learn/paths/18/becoming-a-reactive-web-developer/

2020-03-01 17-52-33
Nikhil Gaur

Nikhil Gaur wrote:

Marcio Carvalho wrote:

Nikhil Gaur wrote:

Hi Marcio,

I think you are using getElementById javascript method to get the container and then setting its style. So while using getElementById keep in mind that you have to use dynamically generated id of the contiiner not the name you entered in service studio for the container.

So you have to do something like this when adding your script in expression:

SyntaxEditor Code Snippet

"<script>var x = document.getElementById("+ContainerName.Id+");
  if (x.style.display === ""none"") {
    x.style.display = ""block"";
  } else {
    x.style.display = ""none"";
  }</script>"

Note the parameter in getElementById. You have to use your container name and use its Id property to concatinate in script.

Yes thats It, im trying with id, but im newbie and i dont know how OS works with javascript, i already saw problems like this, and all of them was doing with nodejavscript, or run javscript action. I dont know how to do it in the simpliest way


Hi Marcio,

If you are doing it in treditional web app then you have to add an expression in the screen and set its excape content property to No. In this expression just add this script as string and it will work like what you want. Just make sure that this expression should come after the container in your screen.

If you are using reactive web app then you can add an oninitialize event on screen and add this script using a js block in the event.

I would also recoment you to complete your web application development training first where you will find answers to most of the queries like this.

https://www.outsystems.com/learn/paths/2/becoming-a-traditional-web-developer/

https://www.outsystems.com/learn/paths/18/becoming-a-reactive-web-developer/

May I know why you want to do this via JS only? Because you can do that using Display (in treditional apps) or Visible (in reactive web apps) property of the containe. Just assign a variable to this property and you have to change value of this property to true and false to show and hide the container.

In Treditional you also have to use ajax refresh.


2020-08-05 08-52-58
Ruben Goncalves

Marcio Carvalho wrote:

When using WebBlock, i want to use javascript to hide a div(container), but im getting undefined funtion call and i dont get it why dont work

Hi Marcio,

It appears that you're trying to invoke your function before it is actually defined...
So the questions is, where the javascript is defined, and where are you invoking it?

Cheers,

Rúben


2021-06-02 20-50-04
Márcio Carvalho

Ruben Goncalves wrote:

Marcio Carvalho wrote:

When using WebBlock, i want to use javascript to hide a div(container), but im getting undefined funtion call and i dont get it why dont work

Hi Marcio,

It appears that you're trying to invoke your function before it is actually defined...
So the questions is, where the javascript is defined, and where are you invoking it?

Cheers,

Rúben


I built the function in either the web block or the template screen,
and I called the function on the button, I already tried on the webblock and outside the webblock on the template screen
2016-04-21 20-09-55
J.
 
MVP

Hi,

I think you need to add some quotes to the get it to work, since it's a string you are passing.

so instead of

document.getElementById("+ContainerName.Id+");

you do :

document.getElementById('"+ContainerName.Id+"');
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.
\"\rNote the parameter in getElementById. You have to use your container name and use its Id property to concatinate in script.\rYes thats It, im trying with id, but im newbie and i dont know how OS works with javascript, i already saw problems like this, and all of them was doing with nodejavscript, or run javscript action. I dont know how to do it in the simpliest way\r\rHi Marcio,\rIf you are doing it in treditional web app then you have to add an expression in the screen and set its excape content property to No. In this expression just add this script as string and it will work like what you want. Just make sure that this expression should come after the container in your screen.\rIf you are using reactive web app then you can add an oninitialize event on screen and add this script using a js block in the event.\rI would also recoment you to complete your web application development training first where you will find answers to most of the queries like this.\r https://www.outsystems.com/learn/paths/2/becoming-a-traditional-web-developer/\r https://www.outsystems.com/learn/paths/18/becoming-a-reactive-web-developer/","dateCreated":"2020-02-06"}}}