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 7087165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:38:24+00:00 2026-05-28T07:38:24+00:00

SOLVED http://jsfiddle.net/ArtofLife/u9d9d/ I have multiple TEXTAREA and BUTTON out side.. For inserting string in

  • 0

SOLVED

http://jsfiddle.net/ArtofLife/u9d9d/

I have multiple TEXTAREA and BUTTON out side.. For inserting string in textarea, I used jQuery plugin (insertAtCaret). How to fill ONLY the last clicked TEXTAREA with text…?

<textarea name="answer_text[0]" cols="50" rows="3" style="width: 99%;">
    AAA
</textarea>

<textarea name="answer_text[1]" cols="50" rows="3" style="width: 99%;">
    BBB
</textarea>

<textarea name="answer_text[2]" cols="50" rows="3" style="width: 99%;">
    CCC
</textarea>

<textarea name="answer_text[3]" cols="50" rows="3" style="width: 99%;">
    Here should be:
    &lt;button class=insert name=insert&gt;Insert&lt;/button&gt; 
</textarea>

<button class=insert name=insert>Insert</button>

<script type="text/javascript">
jQuery.fn.extend({
insertAtCaret: function(myValue) {
    return this.each(function(i) {
        if (document.selection) {
            //For browsers like Internet Explorer
            this.focus();
            sel = document.selection.createRange();
            sel.text = myValue;
            this.focus();
        }
        else if (this.selectionStart || this.selectionStart == '0') {
            //For browsers like Firefox and Webkit based
            var startPos = this.selectionStart;
            var endPos = this.selectionEnd;
            var scrollTop = this.scrollTop;
            this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
            this.focus();
            this.selectionStart = startPos + myValue.length;
            this.selectionEnd = startPos + myValue.length;
            this.scrollTop = scrollTop;
        } else {
            this.value += myValue;
            this.focus();
        }
    });
}
});

var pos = 0;
$('textarea').click(function() {
//Get the name of this clicked item
var pos = $(this).attr("name");
$('.insert').click(function() {
    $('textarea[name^="' + pos + '"]').insertAtCaret('Actual button code');
});
return false;
});
</script>

Now I getting filed all the textareas that I clicked… http://jsfiddle.net/ArtofLife/u9d9d/15/

I want to be filled only the last textarea that is clicked, and not bubbling the variable pos..

  • 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-05-28T07:38:25+00:00Added an answer on May 28, 2026 at 7:38 am

    It is because you have the .insert‘s click handler inside the textarea click handler. Whenever you click on textarea a new handler is attached and it keeps attaching as and when u click on any textarea. Move it outside it will work fine.

    var pos = 0;
    $('textarea').click(function() {
        //Get the name of this clicked item
        pos = $(this).attr("name");
        return false;
    });
    $('.insert').click(function() {
        $('textarea[name^="' + pos + '"]').insertAtCaret('Actual button code');
    });
    

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this: http://jsfiddle.net/uAQ8B/5/ This list should have all the objects on the left
I have a table like this: http://jsfiddle.net/DSvb7/ It currently works normally. However, when I
Could you please have a quick look at the sample code http://jsfiddle.net/vXvs2/ I don't
I have this example http://jsfiddle.net/HnfCU/ I use jQuery to show and hide the .child
Suppose I have markup as setup http://jsfiddle.net/ADxne/ Currently drop downs look like To solve
I have this small testcase: http://jsfiddle.net/sV8js/ You can see that in Chrome (tested on
I have this: http://jsfiddle.net/ETm93/ Now my floated element, leftPanel is having a margin-right: 20px;
I have two examples on jsFiddle: http://jsfiddle.net/9uhfX/1/ http://jsfiddle.net/9uhfX/2/ Example 1 In the first one
Here is a live example of my problem http://jsfiddle.net/littlesandra88/xksB9/ I would have expected that
I've got the following problem (test version available http://jsfiddle.net/qmP8R/2/ ): I have two <div>

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.