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

  • Home
  • SEARCH
  • 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 634769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:19:54+00:00 2026-05-13T20:19:54+00:00

What I am doing is creating a simple html page in which there is

  • 0

What I am doing is creating a simple html page in which there is a textbox. A user posts some input to that textbox such as

first last
first last
first last
first last

Imagine these are different names. What I would like to do is take the input in the textbox, and display it to the screen with the repeating names taken out, in alphabetical order, and with option tags added around them.

What I have

 <div id="contentdisplay"></div>
<FORM action="" method="">
     <p><LABEL for="content">Paste Code Here: </LABEL></p>
     <p><textarea id="content" cols="80" rows="40"></textarea></p>
    </FORM>



 <script type="text/javascript">
  $(document).ready(function() { 
    $('#content').change(function() {
        var test = $('#content').val();
        $("#contentdisplay").html(test);
    });     
   });
  </script>

Right now it takes the value from the textbox when the user clicks outside of it and spits it to the screen inside of the “contentdisplay” div. I’m stuck on the part where I split that user input into lines. I tried test.split(‘/n’) and stuck it into a variable but that did not work out.

My Thoughts on Going About This

  • While looping, Split the form input by newline character, put each line into an array
  • Sort the array into alphabetical order. (Remove any empty lines or spaces before and after the lines during this part.)
  • I’m not sure about removing the doubles. In Java I used a set which automatically only allowed one of each entry to come in.
  • Using jquery’s .html() cycle through array for display and add tags around

Wondering if anyone can enlighten me on my ideas and how I could go about this. Thank you!

Here is the near final version. Thanks to Erik for his help.

Here is what I did to get it where I wanted. Thanks for the help Erik.

<script type="text/javascript">
function process() {

entered = $('#content').val();
lines = entered.split(/\n/); 
opttext = ""; 


lines = jQuery.unique(lines);
lines.sort();

for(var i in lines) {
  opttext += "<option>" + lines[i] + "</option>";
}

$('#contentdisplay').html("<select>"+opttext+"</select>");
}

$(document).ready(function() {
    $("#content").bind('change', process);
});

</script>

<div id="contentdisplay"></div>

<FORM id="myform" action="" method="">
     <p><LABEL for="content">Paste Code Here and click anywhere on the screen: </LABEL></p>
     <p><textarea id="content" cols="40" rows="10"></textarea></p>
</FORM>
  • 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-13T20:19:54+00:00Added an answer on May 13, 2026 at 8:19 pm

    Try this:
    http://jsbin.com/okigi/3/edit
    (edit: changed the form tag to a div so the example doesn’t sumbit anywhere)

    function process() {
    
        entered = $('#content').val();
        lines = entered.split(/\n/);
        opttext = ""; for(var i in lines) {
          opttext += "<option>" + lines[i] + "</option>";
        }
        $('#myform').append("<select>"+opttext+"</select>");
    }
    
    $(document).ready(function() {
        $("#process").bind('click', process);
    });
    
    <FORM id="myform" action="" method="">
         <p><LABEL for="content">Paste Code Here: </LABEL></p>
         <p><textarea id="content" cols="40" rows="10"></textarea></p>
         <button id="process">Go!</button>
    </FORM>
    

    This doesn’t take out duplicates, or put them in alaphabetical order, but once you have the lines in the array “lines” you can figure out how to do those things on your own.

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

Sidebar

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.