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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:19:16+00:00 2026-05-27T23:19:16+00:00

Add multiple items to text-area with duplicate items. I have one text-area which store

  • 0

Add multiple items to text-area with duplicate items.

I have one text-area which store data after clicked add data link.

How can i prevent add duplicate items to text-area?

JavaScript call DOM event:

  var Dom = {
    get: function(el) {
      if (typeof el === 'string') {
        return document.getElementById(el);
      } else {
        return el;
      }
    },
    add: function(el, dest) {
      var el = this.get(el);
      var dest = this.get(dest);
      dest.appendChild(el);
    },
    remove: function(el) {
      var el = this.get(el);
      el.parentNode.removeChild(el);
    }
  };

  var Event = {
    add: function() {
      if (window.addEventListener) {
        return function(el, type, fn) {
          Dom.get(el).addEventListener(type, fn, false);
        };
      } else if (window.attachEvent) {
        return function(el, type, fn) {
          var f = function() {
            fn.call(Dom.get(el), window.event);
          };
          Dom.get(el).attachEvent('on' + type, f);
        };
      }
    }()
  };

JQuery add data to textarea:

    $("#lkaddlanguage").click(function(){


                 var totalstring;
                 var checkconstring = $("#contentlng").text();

                 var strLen = checkconstring.length;
                 myStr = checkconstring.slice(0,strLen-1);
                 //alert(myStr);

                 var checkedItemsArray = myStr.split(";");
                 var j = 0;
                 var checkdup=0;

                totalstring=escape($("#textval").val()) ;

                var i = 0;

                var el = document.createElement('b');
                el.innerHTML = totalstring +";";

                Dom.add(el, 'txtdisplayval');

                Event.add(el, 'click', function(e) {
                  Dom.remove(this);
                });

    });

HTML Display data

<input type="textbox" id="textval">
<a href="#lnk" id="lkaddlanguage" >Add Data</a>
<textarea readonly id="txtdisplayval" ></textarea>
  • 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-27T23:19:17+00:00Added an answer on May 27, 2026 at 11:19 pm

    This seems a very straightforward requirement to me, so I’m not quite clear where you’re getting stuck. I have not tried too hard to figure out your existing code given that you are referencing elements not shown in your html (“contentlng”). Also, mixing your own DOM code with jQuery seems a bit pointless. You don’t need jQuery at all, but having chosen to include it why then deliberate not use it?

    Anyway, the following short function will keep a list of current items (using a JS object) and check each new item against that list. Double-clicking an item will remove it. I’ve put this in a document ready, but you can manage that as you see fit:

    <script>
    $(document).ready(function() {
       var items = {};
    
       $("#lkaddlanguage").click(function(){
           var currentItem = $("#textval").val();
    
           if (currentItem === "") {
               alert("Please enter a value.");
           } else if (items[currentItem]) {
               alert("Value already exists.");
           } else {
               items[currentItem] = true;
               $("#txtdisplayval").append("<span>" + currentItem + "; </span>");
           }
    
           // optionally set up for entry of next value:
           $("#textval").val("").focus();
           return false;
       });
    
       $("#txtdisplayval").on("dblclick", "span", function() {
           delete items[this.innerHTML.split(";")[0]];
           $(this).remove();
       });
    });
    </script>
    
    <input type="textbox" id="textval">
    <a href="#lnk" id="lkaddlanguage" >Add Data</a><br>
    <div id="txtdisplayval" ></div>
    
    <style>
     #txtdisplayval {
        margin-top: 5px;
        width  : 200px;
        height : 100px;
         overflow-y : auto;
        border : 1px solid black;
     }
    </style>
    

    Note I’m using a div (styled to have a border and allow vertical scrolling) instead of a textarea.

    As you can see I’ve coded it to display an alert for duplicate or empty items, but obviously you could remove that and just ignore duplicates (or substitute your own error handling). Also I thought it might be handy to clear the entry field and set focus back to it ready for entry of the next value, but of course you can remove that too.

    Working demo: http://jsfiddle.net/LTsBR/1/

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

Sidebar

Related Questions

I have a Dictionary that when I add multiple values to it, the items
I'm trying to add multiple jQuery data entries to a single element. I suspected
It's very painful to add multiple tickets to Trac or to have it as
runat=server /> But this code is not working How can I add multiple controls
In the below code where T : WsgTypes.RouteRestriction, can I add multiple classes so
Currently we have a table with a bunch of data from a database which
I've got this HTML form where I have multiple input elements: text, radio, and
So i have a page that is gonna have multiple modal popups. Each one
I want to add multiple hyperlink control items to a asp.net listbox control. I
I have a ul with multiple list items and am using jQuery to: Count

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.