Javascript on button in webscreen

Javascript on button in webscreen

  

SyntaxEditor Code Snippet

function a()
{
document.getElementById("button1").style.backgroundColor = "lightblue";

}

i have written this code in javascript property of webscreen. and whenever i call function a(); onclick event of button i get the screen mentioned in screen shot. What wrong i am doing?

Lovish Goyal wrote:

SyntaxEditor Code Snippet

function a()
{
document.getElementById("button1").style.backgroundColor = "lightblue";

}

i have written this code in javascript property of webscreen. and whenever i call function a(); onclick event of button i get the screen mentioned in screen shot. What wrong i am doing?

Hi Lovish,

It is really weird if that's happening. Can you share a module to see what's happening?

I have other suggestions to ask you:

1) Why do you want to run a javascript code when clicking a button? Is your goal to change the button's style?

2) The way a web app is generated, the Id's of the elements in the screen are not always the same (document.getElementId("button1") won't work). You can create a custom property and use it instead.


Regards,

António Pereira


Solution

Hi Lovish, 

As Antonio said document.getElementId("button1") won't work. So instead you can set your function like this

function a(idInput)

{

document.getElementById(idInput).style.backgroundColor = "lightblue";

}


And on the onclick of the button set

"a('"+button1.Id+"');"


Hope it helps,

André 

Solution

Andre Silva wrote:

Hi Lovish, 

As Antonio said document.getElementId("button1") won't work. So instead you can set your function like this

function a(idInput)

{

document.getElementById(idInput).style.backgroundColor = "lightblue";

}


And on the onclick of the button set

"a('"+button1.Id+"');"


Hope it helps,

André 

Thanks silva


Hi,

function Changeclr(id)
{
 $("#"+id).css("background-color","lightblue"); 
}