Software Archive
Read-only legacy content
17061 Discussions

trigger button click event

Marco_S_
Beginner
784 Views

Hi all,

I need to trigger a button click event from my index_user_scripts.js.

I'm using App Framework.

Thanks in advance.

Marco

0 Kudos
6 Replies
SithLord
New Contributor I
784 Views

Try something like

$( "#mybutton" ).trigger( "click" );

 

0 Kudos
Chris_P_Intel
Employee
784 Views

If using the design view, just open the interactivity pane and you'll see your button listed there.  Click on the target on the right and choose "Custom Script...". That'll add an entry for you to that index_user_scripts.js

But, essentially, it's doing something very similar to what SithLord suggested.

0 Kudos
Marco_S_
Beginner
784 Views

Hi all,

thanks for replies. I have to get the same effect of pushing a button, not only execute the code event inside the "click".

For example in c#, vb ecc it´s enough simple by calling the subroutine button_click and the framework also switches the focus on the pushed button.

I hope this clarifies my question.

Marco

 

0 Kudos
Chris_P_Intel
Employee
784 Views

using jQuery:

$("#mybutton").click()
or
$("#mybutton").trigger("click");

See the jQuery docs for 'click' and 'trigger'.

0 Kudos
Chris_P_Intel
Employee
784 Views

Did you consult the jQuery docs for those routines?  You can also test them in the console.

https://api.jquery.com/click/

http://api.jquery.com/trigger/

The code I gave you will not run as written. You'll need to change the CSS selector, minimally.

 

 

0 Kudos
Marco_S_
Beginner
784 Views

Hi all,

maybe I found what I need :

$( '#button1' ).trigger("click");
$( '#button1' ).addClass("pressed");

The effect is to run the code inside the click button, and set the "focus" on the related button.

Sorry but I'm newbie at HTML5, CSS, javascript dev and for a "VisualStudio developer" like me is difficult to explain how I want to get.
 

0 Kudos
Reply