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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:13:16+00:00 2026-05-14T02:13:16+00:00

I have a function that, when the user selects one or more items, it

  • 0

I have a function that, when the user selects one or more items, it moves those items to the top of the list box (still selected) and scrolls to the top so they’re visible. It works in all major browsers that I’ve tested. The problem comes when I have this function sort a listbox inside of a table cell. When I do that and use IE8, it sorts & highlights properly but doesn’t scroll to the top. The JavaScript passes basic JSLint checking and the webpage passes HTML validation. Did I find a quirk with IE8? Am I coding this listbox sort & scroll function the wrong way?

<script type="text/javascript">
function Arrange(obj) {
    var countSel = 0, countNSel = 0, i, arr_selected = [], arr_unselected = [];
    for (i = 0; i <= obj.length - 1; i++) {
        if (obj.options[i].selected) {
            //create array with all selected items then sort it
            arr_selected[countSel] = [];
            arr_selected[countSel][0] = obj.options[i].text;
            arr_selected[countSel][1] = obj.options[i].value;
            countSel = countSel + 1;
            arr_selected.sort();
        }
        else {
            //create array with all UNselected items then sort it
            arr_unselected[countNSel] = [];
            arr_unselected[countNSel][0] = obj.options[i].text;
            arr_unselected[countNSel][1] = obj.options[i].value;
            countNSel = countNSel + 1;
            arr_unselected.sort();
        }
    }
    if (countSel !== 0) {
        //overwrite listbox options with selected items
        for (i = 0; i <= countSel - 1; i++) {
            obj.options[i] = new Option(arr_selected[i][0], arr_selected[i][1]);
        }
        //overwrite listbox options with UNselected items
        for (i = 0; i <= countNSel - 1; i++) {
            obj.options[countSel] = new Option(arr_unselected[i][0], arr_unselected[i][1]);
            countSel = countSel + 1;
        }
    }

    //for showing selected items
    //scroll to the top of the list and select the appropriate items
    //it's in reverse order because IE8 wanted to only scroll to the last item selected
    obj.selectedIndex = 0;
    for (i = arr_selected.length - 1; i >= 0; i--) {
        obj.options[i].selected = true;
    }
}
</script>
</head>
<body>
<form name="frm" action="post">
<table><tr><td>test:</td><td>
<select size="4" name="cbostaffcontact" multiple onblur="Arrange(document.forms[0].cbostaffcontact);">
<option value="user1">Al</option>
<option value="user2">Bob</option>
<option value="user3">Christy</option>
<option value="user4">Jane</option>
<option value="user5">Randy</option>
<option value="user6">Tom</option>
<option value="user7">Zed</option>
</select>
</td></tr></table>
</form>
  • 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-14T02:13:16+00:00Added an answer on May 14, 2026 at 2:13 am

    It’s probably a quirk in IE8, but your code doesn’t actually say anything about scrolling, so I wouldn’t blame IE8. Here is a simple instruction that should solve your problem:

    obj.scrollTop=0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my Controller i have function that runs after user clicks on item, which
I have a model function that updates a user in my CodeIgniter application: //
I have a code like that: User = function(){} User.a = function(){ return try;
I have a log function on my admin panel that checks user input for
I have an user defined table function in SQL Server that aggregate data from
I have the middleware that allows me to check user auth, here is: function
I have a user defined function. In that function I declared a variable of
I have n number of choices in a select box. After the user selects
I have the following html that when a user selects leasehold additional form fields
I have a web application that functions as a dashboard, allowing a user to

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.