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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:24:13+00:00 2026-05-17T00:24:13+00:00

I have a web page with several HTML Select controls that all allow multiple

  • 0

I have a web page with several HTML Select controls that all allow multiple selection. Next to each control we have a “Clear” button that de-selects all selected items in the control, with the onclick that looks something like this:

<input type=button value="Clear" size=5 onclick="selectOptions('n.MyControl', false)">

The called Javascript code looks like this:

function selectOptions(controlName, bSelectItems)
{
    for (i=0; i < document.myForm[controlName].options.length; i++)
    {
        document.myForm[controlName].options[i].selected = bSelectItems;
    }

}

It works really well with the Select controls that allow multiple selection, but I just added a Select control that does not allow multiple selection (i.e. does not have the “multiple” attribute), and this code does not clear it. If I add the “multiple” attribute, the Clear button starts working again, so I know it has something to do with the fact that I am not allowing multiple items to be selected.

My question is, why does the above code not work and more importantly, how can I get my new Select control cleared in JavaScript?

  • 1 1 Answer
  • 1 View
  • 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-17T00:24:13+00:00Added an answer on May 17, 2026 at 12:24 am

    The reason your code doesn’t work is because you are trying to iterate over each option and do something, but since (like you said) the multiple attribute isn’t set, it doesn’t let you modify multiple options.

    As for fixing it, you can try to get the selected option and then just deselect that single option.

    Update:
    I don’t know for sure that this is the ideal solution, but it seems to work for me in IE8.

    document.getElementById('myselect').selectedIndex = -1;
    

    Of course you can get the select element whichever way works best for you, but just set the selectedIndex attribute to -1.

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

Sidebar

Related Questions

I have web forms page that has 2 controls. A gridview and an associated
I have a web page that I display in a WPF WebBrowser control within
I have a web page that pulls in several javascript files in the HEAD
I have an HTML web page (the parent) that contains a hyperlink. When clicked,
On my web page, I'd like to have a group of several concentric circles
I have web page in PHP which displays all records in a table. I
new on rails and using windows for now,, i have web page that user
I have a web page that prompts for user input via DropDownLists in some
I have a web page that whenever your in a text-field, if you hit
I have an ambitious requirement for an asp.net 2.0 web page that contains a

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.