Wednesday, 16 January 2013

Search in a Check-Box list

This is a very important piece of code which is required many a times to search in a Check-box List on a web page. This code requires a text box to enter the search text and a check box list in which this search is to be performed. This code searches the first item in the list starting with the searched text and then scrolls the div up to that searched item.



function SearchBox(ListBox, SearchTextBox, ChkBoxSA, divSel) {
     
        var searchText;
        var arrListBox = new Array(5);
        arrListBox[0] = '<%=chkbxlstFacility.ClientID %>';
        arrListBox[1] = '<%=chkbxlstProductLine.ClientID %>';
        arrListBox[2] = '<%=chkbxlstState.ClientID %>';
        arrListBox[3] = '<%=chkbxlstCountry.ClientID %>';
        arrListBox[4] = '<%=chkbxlstContinent.ClientID %>';

        var abox = document.getElementById(arrListBox[ListBox]);
        var checkBoxArray = abox.getElementsByTagName('input');
        var checkBoxLabel = abox.getElementsByTagName('label');

        for (var j = 0; j < checkBoxArray.length; j++) {
            var checkBoxRefLbl = checkBoxLabel[j];
            var checkBoxRef = checkBoxArray[j];
            if (SearchTextBox.value != "") {
                var ser = checkBoxRefLbl.innerText.toLowerCase();
                var toSer = SearchTextBox.value.toLowerCase();
                if (ser.startsWith(toSer)) {
                    checkBoxRef.focus();
                    divSel.scrollTop = checkBoxRef.offsetTop + 20;
                    break;
                }
            }
            else {
                ChkBoxSA.focus();
                break;
            }
        }
        SearchTextBox.focus(); 
     }


1 comment:

  1. oracle fusion Cloud HCM online training at erptree.com is worlds best online training center. we have excelent knowledge sharing Platform. we have students from all over the world.We have 10+ years of experience, we can serve various ascent people. user friendly website developed for students where you will be provided with all the required details and Self-paced DEMO videos.we have our branches in pune, gurgaon, noida, india, usa, uk, uae, oracle fusion hcm training, fusion Procurement training, fusion hcm, scm training


    Oracle Fusion HCM Training

    ReplyDelete