• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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 🙂

TOPICS
JavaScript

Views

241

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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;')}
}

 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

Yes. "Previous" cursor position, before a checkbox was selected.

So if the text field is already populated:

Lorem ipsum CURSOR Lorem ipsum

The focus point (cursor) should be the insertion point upon trigger release.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

That's what the script does.  You said "The remaining content of this text field (if any) should not be changed".  I interpret that as the value should be appended with the check box name.  If you want it replaced instead of appended you should change;

 

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

 

To

 

this.getField(fldName).value=event.target.name;

 

but you can't access a point within the text string inside the text field value.  You could have the user type a marker for the cursor positon and then replace it like this:

Lorem ipsum -- Lorem ipsum

this.getField(fldName).value=this.getField(fldName).value.replace("--", event.target.name);

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

The script can't access the cursor position.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2024 Aug 20, 2024

Copy link to clipboard

Copied

LATEST

*Remove by author*

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines