on 12-15-2016 6:06 PM
Is there any way to grab the ID of a clicked element in a script? I'm trying to create one script that I can attach to a ton of different clickable objects. Here's a pseudocode example:
var thisid = this.id; // this should return the id of the button, radio button, or clickable area that was clicked. HOWEVER, if you actually write the code like this, it attempts to return the ID of the window itself, not the clicked object.
session.put("triggerID",thisid); // stores the ID as a variable
session.utils.executeScript("wnd[0]/doClickAction"); // executes a script that will read the triggerID and run code depending on the ID
If I'm able to do something like this, I can have one script that I link to ALL clickable objects, rather than creating one for each.
Thanks in advance!
The script registered for the onClick event will receive a "source" parameter indicating which object is the source of the event. This is the same object you get from session.findById, so you can use for example "source.id" to get the object ID.
Is that what you are looking for?
I'm not completely sure having a single script for all your events is such a great idea. Why do you want to do this rather than having separate scripts for each event?
Steve.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Steve,
source.id works perfectly, thanks!
In my use-case, we have a lot of radio buttons whose actions are similar but slightly different. By combining these into one file, I'm able to avoid a ton of code duplication, plus copying and pasting code snippets (such as long IDs) is dramatically easier when it's spread out among less files. Unless I run into big problems with this approach I'd encourage lots of users to consider working like this!
Thanks again!
-Dan
User | Count |
---|---|
85 | |
10 | |
9 | |
9 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.