Associate value with mouse double click (hotclick)

Hi, may I ask a script correction? I would like to associate a text with mouse double click in a field. This script works in part:

const field = document.querySelector('ID')
field.addEventListener("dblclick", (e) => {field.value = 'some text'});

The problem is that the text I type in the field gets cleared when I re-doubleclick.
Thank you!.

What do you WANT it to do instead?

Here’s a video explanation, Hutley

The video states the problem, not the expected result. From what I can see, your script does exactly what you’ve told it to do. “When i doubleclick the box, set the text in the box to ‘text’.”

I would simply like to associate a double click with a standard text, without anything being deleted every time I type. So a sort of hotkey

So you want it to ADD the text on double click. Do you want it to add the text at the beginning of what was typed, or at the end?

At any point of a text.

so at the end (of where it is when you double click). Sure.

field.value = field.value + "some text"

(for those that follow: Yes I know I can shorthand that, but i’m demonstrating the full form so it’s easier to understand what’s happening)

2 Likes

It works fine now, thanks m_hutley!!!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.