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(); 
     }


3 comments:

  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
  2. Hiii!!! good moring!!!
    Nice blog. Really helpful information about<a href="http://rainbowtraininginstitute.com/a>Hello Every one. I am Madhu Sudhan from Hyderabad. I have joined Fusion HCM course at rainbow. Thanks to rainbowtraininginstitute for providing such a wonderful training

    ReplyDelete
  3. I am technology Enthusiast. Your blog is really awesome, attractive and impressive. I like the way you think. it is very useful for Java SE & Java EE Learners. Your article adds best knowledge to our Java Online Training India. or learn thru Java Online Training India Students. or learn thru JavaScript Online Training India. Appreciating the persistence you put into your blog and detailed information you provide. Kindly keep blogging.

    ReplyDelete