Click here to Skip to main content
       

JavaScript

 
GeneralRe: Creating a vertical auto-hide toolbar Pinmembern.podbielski28-Sep-12 12:51 
GeneralRe: Creating a vertical auto-hide toolbar Pinmemberjkirkerx29-Sep-12 19:24 
GeneralRe: Creating a vertical auto-hide toolbar Pinmembern.podbielski29-Sep-12 22:04 
QuestionFantastic site demonstrating and teaching "responsive" UI concepts using JavaScript, HTML 5, etc. PinmemberBillWoodruff25-Sep-12 13:46 
AnswerRe: Fantastic site demonstrating and teaching "responsive" UI concepts using JavaScript, HTML 5, etc. PinmemberSteve Bondy7-Dec-12 12:38 
QuestionUsing Jquery in DataList Pinmembermrkeivan19-Sep-12 6:17 
AnswerRe: Using Jquery in DataList Pinmemberjkirkerx25-Sep-12 18:01 
AnswerRe: Using Jquery in DataList Pinmembergjllyl9-Oct-12 19:36 
QuestionHow to calculate difference between two dates PinmemberRobymon17-Sep-12 23:46 
AnswerRe: How to calculate difference between two dates PinmemberJoan Murt18-Sep-12 4:59 
Questionfyi: accidental find: using JavaScript DOM in browser to parse a URL PinmemberBillWoodruff14-Sep-12 22:54 
AnswerRe: fyi: accidental find: using JavaScript DOM in browser to parse a URL Pinmemberziggyfish10-Oct-12 6:26 
Questiongoogle map splite write problem Pinmemberchogrf13-Sep-12 2:48 
QuestionFastest way to select all elements in a *ListBox* PinmemberA*****12-Sep-12 19:32 
I am trying to select all the elements in a Listbox/SelectBox.
 
At the moment I am using the following function *which is working*, the only thing is it takes around 10 seconds to select all elements(of which there are 652).
 
I'm a beginner at javascript so I was wondering whether anyone knew of a faster way to select all elements.
 
//selectBox is the selectbox ID, selectall is a boolean whether to select all elements,
//ensureOneSelected applies when false is specified for selectall
//it then ensures that the first element is always selected.

<script>
 
function selectAll(selectBox, selectAll, ensureOneSelected) {
    // have we been passed an ID
    var selectBoxElement = null;
    var selectBoxOption = null;
 
    var boolSelect = selectAll;
 
    if (typeof selectBox == "string") {
        selectBoxElement = document.getElementById(selectBox);
        selectBoxOption = selectBoxElement.options;
    }
    // is the select box a multiple select box?
    if (selectBoxElement.type == "select-multiple") {
        var max = (selectBoxOption.length);
 
        var modMaxUnrollFactor = (max % 4);
 
        max -= modMaxUnrollFactor ;
 
        for(var i = 0; i < max; i+=4){
            selectBoxOption[i].selected = boolSelect;
            selectBoxOption[i + 1].selected = boolSelect;
            selectBoxOption[i + 2].selected = boolSelect;
            selectBoxOption[i + 3].selected = boolSelect;
 
        }
        for (var i = max; i < selectBoxOption.length; i++) {
            selectBoxOption[i].selected = boolSelect;
        }
 
        if (typeof ensureOneSelected == "boolean") {
            if(selectBoxOption[0].selected == false)
            {
                selectBoxOption[0].selected = ensureOneSelected;
            }
        }
    }
}
</script>
 
thanks in advance
My blog:[^]

AnswerRe: Fastest way to select all elements in a *ListBox* PinmemberBobJanova12-Sep-12 23:04 
GeneralRe: Fastest way to select all elements in a *ListBox* PinmemberA*****13-Sep-12 12:27 
GeneralRe: Fastest way to select all elements in a *ListBox* PinmemberA*****13-Sep-12 18:55 
Questionjavascript _> activex passing by reference PinmemberJohan000112-Sep-12 1:40 
AnswerRe: javascript _> activex passing by reference Pinmembertwseitex16-Sep-12 1:09 
GeneralRe: javascript _> activex passing by reference PinmemberJohan000117-Sep-12 0:46 
GeneralRe: javascript _> activex passing by reference Pinmembertwseitex17-Sep-12 8:30 
GeneralRe: javascript _> activex passing by reference PinmemberJohan000117-Sep-12 21:38 
GeneralRe: javascript _> activex passing by reference Pinmembertwseitex18-Sep-12 8:58 
GeneralRe: javascript _> activex passing by reference PinmemberJohan000118-Sep-12 23:28 
GeneralRe: javascript _> activex passing by reference PinmemberJohan000117-Sep-12 1:03 
AnswerRe: javascript _> activex passing by reference [modified] PinmvpManfred R. Bihy19-Sep-12 1:02 
GeneralRe: javascript _> activex passing by reference PinmemberJohan000119-Sep-12 2:02 
GeneralRe: javascript _> activex passing by reference PinmvpManfred R. Bihy19-Sep-12 2:06 
GeneralRe: javascript _> activex passing by reference PinmvpManfred R. Bihy19-Sep-12 2:12 
QuestionCreate AD block functionality for my website Pinmemberswayam.test1.gmail10-Sep-12 19:58 
AnswerRe: Create AD block functionality for my website Pinmemberenhzflep11-Sep-12 22:06 
QuestionHow does Google show_ads.js work? Pinmemberswayam.test1.gmail10-Sep-12 19:57 
QuestionHow to send request data from one tab to other tab which are on same jsp Pinmembermayureshdh9-Sep-12 18:52 
Questionjavascript/jquery [modified] Pinmemberchaim_zvi8-Sep-12 8:50 
Questionshow alert in javascript and not continue Pinmemberptvce6-Sep-12 21:26 
AnswerRe: show alert in javascript and not continue PinmemberJ4amieC6-Sep-12 22:11 
GeneralRe: show alert in javascript and not continue Pinmemberptvce6-Sep-12 22:30 
AnswerRe: show alert in javascript and not continue PinmemberMKAdeel13-Sep-12 1:22 
GeneralRe: show alert in javascript and not continue Pinmemberptvce16-Sep-12 20:22 
QuestionPython Pygame Newbie Code Help Pinmemberjohtnkucz31-Aug-12 12:14 
QuestionProgress Bar PinmemberManish K. Agarwal31-Aug-12 3:33 
AnswerRe: Progress Bar PinmemberC-War1-Sep-12 4:50 
GeneralRe: Progress Bar PinmemberManish K. Agarwal2-Sep-12 19:22 
AnswerRe: Progress Bar Pinmembertwseitex2-Sep-12 8:24 
GeneralRe: Progress Bar PinmemberManish K. Agarwal2-Sep-12 19:51 
GeneralRe: Progress Bar Pinmembertwseitex4-Sep-12 3:18 
Questionget the checkbox index or table row index with javascript Pinmemberosmanjan30-Aug-12 13:01 
AnswerRe: get the checkbox index or table row index with javascript Pinmemberenhzflep30-Aug-12 13:26 
GeneralRe: get the checkbox index or table row index with javascript Pinmemberosmanjan30-Aug-12 13:45 
GeneralRe: get the checkbox index or table row index with javascript Pinmemberenhzflep30-Aug-12 14:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 29 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid