Skip to main content
Participating Frequently
August 20, 2024
Question

Mouse up inserts value (e.g. checkbox' name) at the cursor position in a text field of my choice.

  • August 20, 2024
  • 2 replies
  • 734 views

I can't seem to get the following the work:

A mouse up trigger, should print/write the name of the corresponding checkbox into any text field in which the cursor was previously positioned. The remaining content of this text field (if any) should not be changed, only the name of the checkbox should be inserted at the (previous) cursor position, before the mouse up trigger was set off.

Is this even possible without a struggle?

Thanks a bunch in advance for any hints and help 🙂

This topic has been closed for replies.

2 replies

PDF Automation Station
Community Expert
Community Expert
August 20, 2024

You would have to insert the following script as an On Blur event into every text field:

var fldName=event.target.name;

Then insert the following Mouse Up action into the check box field:

if(fldName)

{this.getField(fldName).value=this.getField(fldName).value+event.target.name}

Every time the check box is clicked though, it will add it's name to the existing text in the text field.  Are you sure this is what you want?  You might want to test whether the text field already contains the check box name first like this:

 

if(fldName)
{
if(!new RegExp(event.target.name).test(this.getField(fldName).value))
{
this.getField(fldName).value=this.getField(fldName).value+event.target.name;
}
}

 

To add the script to every text field in the document, run the following script in the console:

 

for(var i = this.numFields - 1; i > -1; i--)
{
var oFld = this.getNthFieldName(i);
if(this.getField(oFld).type=="text")
{this.getField(oFld).setAction('OnBlur','var fldName=event.target.name;')}
}

 

 

 

 

 

Participating Frequently
August 20, 2024

Thank you for the quick reply! 🙂

I have a quasi operating console with icons (on which the checkboxes are positioned).

Upon mouse up, a value (e.g. just the name of the checkbox) should be inserted on cursor position in one text field (of several options). Not appended, but on cursor position.

The append only function works fine, just not the cursor part.

PDF Automation Station
Community Expert
Community Expert
August 20, 2024

What do you mean cursor position?  I thought you asked for the value to be inserted into the last text field that had the focus.

try67
Community Expert
Community Expert
August 20, 2024

No. You can't know where the user has clicked into the field and insert the text there.