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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:40:57+00:00 2026-05-29T08:40:57+00:00

I am working on a drop down list. The initial HTML code is as

  • 0

I am working on a drop down list. The initial HTML code is as follows:

<p><a class="link">Milk</a> <a class="link">Sugar</a><a href="" class="view">View  All</a></p>
    <select id="list">

    </select>

When I click on the links the Text (Milk, Sugar, Honey) needs to be added inside the list e.g.
When I click on Milk it should be added to the select list.

So this way if I continue clicking the remaining 2 links they also need to append to the list. I have managed to get thru to the part where I can append the list.

The problem I am facing is with validation of the items in the list. if the 3 items (Milk, Sugar, Honey) already exists in the list it should not be added when I click again.

Also, when i click on viewAll I want to gather all the Items inside the list and show them under the list as 1. Milk
2. Sugar
3. Honey

Can anyone help me with the following: The Validation for duplicate entry and then to display the list.

My jQuery Code is as follow:

var status = null;
var isEmpty = null;
var isFull = null;
var count = 0;
var newStatus = true;

$(".link").bind("click", function(a) {
    var clickItem = a.target.text;
    //alert (clickItem);
    checkIsEmpty();
    appendClickValue(status, clickItem);
});

$(".view").click(function() {
    checkIsEmpty();
    if (newStatus ==true && count == 0)  {
        alert ("Is Empty " + status);
        }
    else if (newStatus == false && count == 1) {
        alert ("Is Full " + status);
        }
});

function checkIsEmpty() {   
    if ($("#list option").length <= 0) { 
        isEmpty = true;
        status = isEmpty;
    } 
    else if ($("#list option").length >= 1) {
        isFull = true;
        status = isFull;
        }

}

function appendClickValue (checkStatus, newItem) {
    //validateItems();
    if (status == true) {       
            $("#list").append("<option>" + newItem + "</option>");      
            count = 1;
            newStatus = false;
        }
}

Also, since I am a beginner I would really appreciate if you could comment the code so I can understand better.

  • 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-29T08:40:58+00:00Added an answer on May 29, 2026 at 8:40 am

    Why so complicated?

    HTML:

    <ul id="itemsList">
        <li><a href="#">Milk</a></li>
        <li><a href="#">Sugar</a></li>
        <li><a href="#">Honey</a></li>
    </ul>
    <select name="itemsSelect" id="itemsSelect"></select>
    <button id="viewAll">View All</button>
    <ul id="result"></ul>
    

    jQuery:

    // Cache for speed
    var $itemsSelect = $('#itemsSelect'),
        $result = $('#result');
    
    $('#itemsList').find('a').click(function(){
        var _value = $(this).text();
    
        // if select doesn't already contain an option 
        // with `_value` text then add it
        if (!$itemsSelect.has('option:contains('+ _value +')').length) {
            $('<option>'+ _value +'</option>').appendTo($itemsSelect);
        }
    });
    
    $('#viewAll').click(function(){
        $result.empty(); // clear list first
        $itemsSelect.find('option').each(function(){
            var _value = $(this).text();
            $('<li>'+ _value +'</li>').appendTo($result);
        });
    });
    

    Example http://jsfiddle.net/H2SeT/5/

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

Sidebar

Related Questions

The following code is taken from a perfect working drop down list, and then
The ASP.net page I am currently working on has a drop down list that
I'm working on drop down menus for this: http://www.heroicdreams.com/wordpress/elderFlashSite.html In every other browser it
I am trying to create a drop down list i have it working but
I am trying to create a drop down list. I have it working but
I have this to populate a drop down list in an ASP.NET MVC view.
The website I am working on will contain a drop-down list that shows a
I have a drop down list that appears throughout my site. For code re-usability
I have a drop down list that is populated by inspecting a class's methods
I have created a partial view to handle drop down list controls. In my

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.