Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:32:53+00:00 2026-06-13T04:32:53+00:00

jsFiddle: http://jsfiddle.net/fThMa/2/ Clicking inside the note / rend text fields and then double clicking

  • 0

jsFiddle: http://jsfiddle.net/fThMa/2/

Clicking inside the note / rend text fields and then double clicking any of the 4 TDs below inserts into the note / rend textfields appropriate HTML entities, even removing highlighted text and inserting at the current cursor position.

What should happen is: Click in note, then double click an entity, then double click an entity again. The result should be one entity inserted into the note text field where the cursor was and further double click events stop.

The problem is, if someone clicks outside the note / rend text fields without dblclicking an entity TD, then that dblclick event handler is never removed. Only until they double click an entity and have that entity inserted is the dblclick event handler removed.

Another bug is, every time note / rend is given focus, a new event handler is created and attached, so that if I click note / rend several times and then double click an entity, that entity is inserted for each time I originally clicked on note / rend.

What would be the best way to get this to only fire once and only create a single event handler?

Moving the .off outside the .on removes the .on as soon as it is set, never letting the function in .on to run.

(function ($, undefined) {
        $.fn.getText = function() {
            var elem = $(this).get(0);
            var posStart = 0;
            
            if('selectionStart' in elem) {
                if (elem.selectionStart > elem.selectionEnd) {
                    posEnd = elem.selectionStart;
                    posStart = elem.selectionEnd;
                } else {
                    posEnd = elem.selectionEnd;
                    posStart = elem.selectionStart;
                }
                if (posStart != posEnd) {
                    $(elem).val($(elem).val().substring(0, posStart) + $(elem).val().substring(posEnd));
                }
            }
            return posStart;
        }
    })(jQuery);
        
    $(document).ready(function() {
        $("#attributes table tr td").on("blur", "input", function(event) {
            var elem = $(this);
            $("#entities table").one("dblclick", "tr", function(event) {
                var cursorPos = $(elem).getText();
                var entity = $(this).children(":first").children(":first").val();
                var beg = $(elem).val().substring(0, cursorPos);
                var end = $(elem).val().substring(cursorPos);
                $(elem).val(beg + entity + end);
                $("#entities table").off("dblclick", "tr");
            });
        });
    });​

<div id="attributes">
  <table>
    <form>
      <tr>
        <td><p>note</p></td>
        <td><input id="note" name="note" type="text" value="note"></td>
      </tr>
    </form>
    <form>
      <tr>
        <td><p>rend</p></td>
        <td><input id="rent" name="rend" type="text" value="rend"></td>
      </tr>
    </form>
  </table>
</div>
<div id="entities">
  <table>
    <form>
      <tr>
        <td><input id="ent1-val" hidden="true" type="text" value="&amp;lt;"></td>
        <td><input id="ent1-vis" type="text" value="<"></td>
        <td><input id="ent1-name" type="text" value="Less Than"></td>
      </tr>
    </form>
    <form>
      <tr>
        <td><input id="ent2-val" hidden="true" type="text" value="&amp;gt;"></td>
        <td><input id="ent2-vis" type="text" value=">"></td>
        <td><input id="ent2-name" type="text" value="Greater Than"></td>
      <tr>
    </form>
  </table>
</div>​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:32:55+00:00Added an answer on June 13, 2026 at 4:32 am

    I would suggest unbinding the event when the event that binds it gets triggered, preventing the doubleclick event from being bound twice. You may also want to unbind it after n seconds, or possibly after clicking elsewhere on the page.

    $("#entities table").off("dblclick","tr")
                        .on("dblclick", "tr",
                               function() {
                                   //do stuff 
                               });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the JsFiddle: http://jsfiddle.net/d6mmZ/7/ Clicking links 1 and 2 updates the text instantly. Clicking
Going a little insane here. Here is the jsfiddle: http://jsfiddle.net/mersenneprimes/CvGKK/ Note business is in
The jsFiddle: http://jsfiddle.net/hbrls/Snn87/12/ I have a verify code field: <input type=text id=verfy_code name=verfy_code class=required
jsfiddle: http://jsfiddle.net/ztNHL/3/ Select the top input, and then tab to the second. It will
jsfiddle: http://jsfiddle.net/FgZnK/1/ Clicking on the box goes to a page not found. How can
Here is the jsFiddle: http://jsfiddle.net/JFwDw/2/ What I'm wanting to do is use links to
Here is the jsfiddle : http://jsfiddle.net/hhimanshu/sYLRq/ Current Click on Add to list and drop-down
Hi I have setup the following jsFiddle http://jsfiddle.net/a9ugu/2/ I am wondering why I get
Have a look at this jsfiddle: http://jsfiddle.net/Dh96F/1/ The Expand button will animate the widening
Here is the link to the jsfiddle: http://jsfiddle.net/d3xMZ/ when I hover, it does exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.