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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:18:29+00:00 2026-06-05T19:18:29+00:00

I have a select dropdownlist with 1 item selected at page load in html.

  • 0

I have a select dropdownlist with 1 item selected at page load in html.

<select name = "options">
  <option value = "1">Item1</option>
  <option value = "2" selected>Item2</option>
  <option value = "3">Item3</option>
  <option value = "4">Item4</option>
</select>

Now I want to capture new select option when user press shift and select another option such as “Item 3”.

I have the following code to find all the selections in the list

 var value = "";
 for (var intLoop = 0; intLoop < Form.elements[index].length; intLoop++) {

     if(Form.elements[index][intLoop].selected )
             value = value + Form.elements[index][intLoop].value;
 }

I can see the “Item 2” and “Item 3” are selected but i want to get capture “Item 3” only. Is it possible?

  • 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-05T19:18:31+00:00Added an answer on June 5, 2026 at 7:18 pm

    Here’s code that will tell you what has been selected and what has been deselected http://jsfiddle.net/8dWzB/

    It uses Array.prototype.indexOf, and it’s not the fastest way to do it. But it should get you going in the right direction.

    HTML

    <select id="options" multiple="multiple">
      <option value = "1">Item1</option>
      <option value = "2" selected>Item2</option>
      <option value = "3">Item3</option>
      <option value = "4">Item4</option>
    </select>
    

    JS

    function getSelectedIndexes(select) {
       var selected = [];
       for (var i = 0; i  < select.options.length; i++) {
           if(select.options[i].selected ) {
                selected.push(i);
           }
       }
       return selected;
    }
    
    var select = document.getElementById("options");
    var prevSelected = getSelectedIndexes(select);
    
    select.onchange = function(e) {
        var currentlySelected = getSelectedIndexes(this);
    
        for (var i =0; i < currentlySelected.length; i++) {
            if (prevSelected.indexOf(currentlySelected[i]) == -1) {
                console.log("Added to selection ", this.options[currentlySelected[i]].text);
            }
        }
    
        for (var i =0; i < prevSelected.length; i++) {
            if (currentlySelected.indexOf(prevSelected[i]) == -1) {
                console.log("Removed from selection  ", this.options[prevSelected[i]].text);
            }
        }        
        prevSelected = currentlySelected;
    };
    ​
    

    If you really only want to know which item was last clicked, you can use the following code. I’ll use jQuery so I can easily set a handler on all the option objects. Remember this won’t work if you change the selection with the keyboard

        $('option').click(function(e){
            var parentNode = this.parentNode;
            for (var i=0; i < this.parentNode.options.length; i++) {
                if (parentNode.options[i] == this) {
                  console.log('Clicked item with index', i);
                  break;
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: @Html.DropDownList(ddlCouponsAppointment, Model.Coupons.Select(a => new SelectListItem { Text = a.Name, Value
I have the following code in a view: <div class=wrap_select> @Html.DropDownList(dateRange, new SelectList(Model.DateRange, Value,Text),
I have the following dropdown list: <select id=dropdown> <option value=AB>Alberta Standards</option> <option value=BC>British Columbia
So I have a dropdown list <select id=theSelectId> <option value=volvo>Volvo</option> <option value=saab>Saab</option> <option value=mercedes>Mercedes</option>
If i have a dropdown list that looks like this: <select id=select> <option value=Armoire>Armoire</option>
I have select option in my page or drop down list,my problem is how
I have an edit page with a Html.DropDownList in it....I cant show the dropdownlist
I have a drop down list on my web page, the selected item of
How do I keep the selected item after I submit the page? I have
On an aspx page I have a dropdownlist and a button. I select 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.