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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:28:40+00:00 2026-05-25T21:28:40+00:00

I am trying to prevent printing duplicated values from a listbox to a label,

  • 0

I am trying to prevent printing duplicated values from a listbox to a label, this is what I did but apparently it’s not right, there’s not errors but nothing is printed out to my label, if I remove this line:

if (arSelected.indexOf(selectBox.option[i].selected == -1))

it prints out the values but apparently everytime I click and highlight on the values in the listbox, it’s going to print them out again to my label. Please kindly advice. Thanks!

<select multiple size="8" style="width: 135px" onBlur="selectAl ('QualMemTypeToBox',true)"  id="QualMemTypeToBox"></select>

function selectAll(selectBox, selectAll) {
        var arSelected = "";
        // have we been passed an ID
        if (typeof selectBox == "string") {
            selectBox = document.getElementById(selectBox);
        }
        // is the select box a multiple select box?
        if (selectBox.type == "select-multiple") {
            for (var i = 0; i < selectBox.options.length; i++) {
                selectBox.options[i].selected = selectAll;

                if (arSelected.indexOf(selectBox.option[i].selected == -1)) {

                    document.getElementById('<%=uilblDestinationQualMemType.ClientID%>').innerHTML += selectBox.options[i].value + " | ";
                    arSelected += selectBox.options[i].selected;
                }
             }
        }
    }
  • 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-25T21:28:40+00:00Added an answer on May 25, 2026 at 9:28 pm

    try:

    function selectAll(selectBox, selectAll) {
        var arSelected = "";
        // have we been passed an ID
        if (typeof selectBox == "string") {
            selectBox = document.getElementById(selectBox);
        }
        //reset the label every time the function is called
        document.getElementById('<%=uilblDestinationQualMemType.ClientID%>').innerHTML="";
    
        // is the select box a multiple select box?
        if (selectBox.type == "select-multiple") {
            for (var i = 0; i < selectBox.options.length; i++) {
                selectBox.options[i].selected = selectAll;
                //make sure you process only items that have been checked
                //AND you need to track the VALUE of the <option>
                //NOT the "selected" attribute
                if (selectBox.options[i].selected && arSelected.indexOf(selectBox.options[i].value) == -1) {
    
                    document.getElementById('<%=uilblDestinationQualMemType.ClientID%>').innerHTML += selectBox.options[i].value + " | ";
                    //here is where you actually update the variable with the VALUE
                    //of the <option>, not the "selected" attribute
                    arSelected += selectBox.options[i].value;
                }
             }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not that I'm trying to prevent 'View Source' or anything silly like that, but
Trying to prevent the application from shutting down when clicked the X button, it
I'm trying to prevent my Greasemonkey script from executing within IFRAMEs. I'm doing so
I'm trying to prevent a user from disabling style.(I HAVE A GOOD REASON TO
I am trying to prevent the enter key from being put into a textarea,
I am trying to prevent the app log messages from going out to STDOUT
I am trying to prevent data races in a multihreaded server. My problem is
The question covers most of it, but I'm trying to present a well articulated
Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and

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.