Copy link to clipboard
Copied
Hello All,
First time post here, but I couldn't find anything on this particular subject so I felt I needed to reach out.
I have a document with hundreds of checkboxes. I'm trying to instruct these checkboxes to run a document level code on mouseup, but in order for it to run correctly, I need the name of the checkbox field being checked/unchecked. I am currently doing this by looping through all fields in the document, but it's causing the document to be really slow.
I've tried using event.source.name and other variants, but no luck.
Any help would be appreciated.
Copy link to clipboard
Copied
It's event.target.name, actually.
Copy link to clipboard
Copied
// name of active field
var strFldName = event.target.name;
// if field's name contain "text-12"
if (/text-12/.test(strFldName)) {
// your script here
}
PDF Acrobatic, InDesigner & Photoshoptographer
Copy link to clipboard
Copied
It's event.target.name, actually.
Copy link to clipboard
Copied
// name of active field
var strFldName = event.target.name;
// if field's name contain "text-12"
if (/text-12/.test(strFldName)) {
// your script here
}
PDF Acrobatic, InDesigner & Photoshoptographer
Copy link to clipboard
Copied
Thanks very much, JR.
It wouldn't work until I added an additional line passing the "event.target.name" to a variable.
// I was trying this...
functionName(event.target.name);
// This is what worked
var myName = event.target.name
functionName(myName);
Copy link to clipboard
Copied
This is a bit dangerous to use, because if you use this method to look for "text-1", for example, it will match both "text-1", as well as "text-10", "text-11", "text-115", etc.
Copy link to clipboard
Copied
try67 is right, you should use this instead, "\b" means "word limit":
if (/\btext-12\b/.test(strFldName)) {
PDF Acrobatic, InDesigner & Photoshoptographer
Copy link to clipboard
Copied
Not sure why you need a regular expression at all... You can just do a simple comparison, like this:
if (event.target.name=="text-12") {
Copy link to clipboard
Copied
Many thanks to you both for your feedback on this.
I took the time to rename all of the checkboxes before starting this, but I appreciate you two bringing this point up.
This is really a simple bit of code to highlight a premade selection of text when the corresponding checkbox is selected (to make selections more easily visible). In case anyone else comes up on a similar problem, I'll include my code below.
// code in each checkbox
var myName = event.target.name;
var myPage = this.pageNum;
hiLighter(myName, myPage);
//document level javascript function
function hiLighter(myName, myPage)
{
var curField = this.getField(myName);
if (curField.type == "checkbox") {
var hiLite = this.getAnnot(myPage, "HL."+myName);
if (hiLite != null){
if (curField.value == "Yes") hiLite.hidden = false;
if (curField.value == "Off") hiLite.hidden = true;
}
}
}

