24
Views
13
Comments
Solved
Triggering a button through JavaScript (cannot read property 'click' of undefined )
Application Type
Traditional Web

Hello so I'm using a forge application called WidgetLibrary40, and I'm trying to trigger a button so I can run a server action, but it appears an error on the console. At the moment I'm calling this function that triggers the click 

function executeNavigationAction()  {

  document.getElementById('"+ok.Id+"').click();

}

The function works but the click doesn't, thank you for your help.

Screenshot42.png

Rank: #25893
Solution

Hello everybody,

Just want to say thank you for your help, what I did to solve the problem was instead of trying to click the button to run the screen action, I created a parameter in JavaScript that allows me to pass the data I needed. Thank you anyway for your help.

Regards,

Daniel

Rank: #603

Hi Daniel,

From the error, it seems to be JS not able to get the element by Id so please check the document.getElementById should have appropriate Id

If possible could you please share oml, so we can track the error

Regards,

Krushna

Hi Daniel,

Do you only want to trigger the button through JavaScript? If you are doing it in a screen action then you can use Widget_Click server action present in rich Widget component.  You can add through the manage dependencies.

You need to provide the id to trigger and it should work for you.

Let me know if this helps. 

Thanks,

Unnati K

mvp_badge
MVP
Rank: #78

Hi Daniel,

Could you please share bit more information for the mentioned case like:

1) Where does the executeNavigationAction function definition is defined (expression or JavaScript section)?

2) From where/How exactly you are invoking the executeNavigationAction function?

3) Is it that you have defined a button widget named ok and its runtime Id property is ok.Id?

If you can share code/implementation screen shots with us instead of complete .oml file, it will help us to understand the case much better. 


Kind regards,

Benjith Sam

Rank: #329

Hi Daniel,

Please check if the quotes you are using in the expression are correct? Try executing the same command in the browser console and check if this works(You can use inspect element to check the proper ID). Then  you should be able to get the exact issue if the id you are providing is correct or not.

Thanks,

Swapnil

Hi Daniel,

Solution: 1

After rendering the page Id of ok button will be changed so you can not call like document.getElementById('"+ok.Id+"').click();  if you want to call through javascript then you can assign some class  to control  like below 

and you can use this class in javascript to identify that control.

Solution 2: You use Widget_Click function to trigger the button click.

Regards

Shashikant Shukla


Rank: #25893
Solution

Hello everybody,

Just want to say thank you for your help, what I did to solve the problem was instead of trying to click the button to run the screen action, I created a parameter in JavaScript that allows me to pass the data I needed. Thank you anyway for your help.

Regards,

Daniel