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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:26:34+00:00 2026-06-02T14:26:34+00:00

i build a small function its adds drop down value to div, but my

  • 0

i build a small function its adds drop down value to div, but my requirement it that whenever name add in div it suppose to come in new line and it should be in ascending order, i tried it but i am not reaching up to the solution.

http://jsfiddle.net/a7Y3m/1/

<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $(function(){
        var str = "";       
        $('#me').change(function(){
            str += $(this + "option:selected").text() 
            $('#text').text(str)
        })
    });
    </script>
    <style>
    .main {
        margin:0 auto;
        width:500px;
        border:solid 1px #F00;
        height:500px
    }
    #text{ margin-left:50px; margin-top:50px; font:24px/18px Tahoma, Geneva, sans-serif; color:#F00}
    </style>
</head>
<body>
    <div class="main">
        <select id="me">
        <option>first</option>
        <option>second</option>
        <option>third</option>
        <option>fourth</option>
        </select>
        <div id="text"></div>
    </div>
</body>
  • 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-02T14:26:35+00:00Added an answer on June 2, 2026 at 2:26 pm
    $(function(){   
        var strings = []; // Use an array instead of strings
    
        $('#me').change(function(){
            // Add the current value to the array
            strings.push($(this + "option:selected").text());
            // Sort the array
            strings.sort();
            var res = "";
    
            // Concatenate the sorted values of the array
            // and add a newline to each value
            for(var i = 0; i < strings.length; ++i)
                res += strings[i]+' \n';
    
            // Display the text
            $('#text').text(res);
        });
    });
    
    #text{
       white-space:pre; // Don't ignore the newlines.
    }
    

    JSFiddle

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

Sidebar

Related Questions

I'm trying to build a small program that hosts vst effects and I would
I'd like to build a small Python program that can listen to and analyze
I'm trying to build a small class-like container that will make it a little
i am trying to build a small email worker that sends my emails. The
I want to build a small App that will recognize any Bluetooth headset connection
i have build a small function whose work is to change banner image path
I plan to build a small audio-recorder app in C#. My laptop has a
i have build a small test app in Flash Pro 5.5 overlayed with the
I'm trying to build a small language with similar syntax and grammatical structure to
I'm trying to build a small testing app with erlang+mnesia. I have a user

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.