Tuesday, October 31, 2017

কি বোর্ড এর আপ ডাউন বাটন ক্লিক করে জাভাস্ক্রিপ্ট দিয়ে টেবিলের রো সিলেক্ট

(function () {
    var trows = document.getElementById('table_Return').rows, t = trows.length, trow, nextrow,
        //  rownum = document.getElementById('rownum'),
        addEvent = (function () {
            return window.addEventListener ? function (el, ev, f) {
                el.addEventListener(ev, f, false); //modern browsers
            } : window.attachEvent ? function (el, ev, f) {
                el.attachEvent('on' + ev, function (e) { f.apply(el, [e]); }); //IE 8 and less
            } : function () { return; }; //a very old browser (IE 4 or less, or Mozilla, others, before Netscape 6), so let's skip those
        })();

    // rownum.value = rownum.defaultValue; //reset for browsers that remember input values on reload

    while (--t > -1) {
        trow = trows[t];
        trow.className = 'normal';
        addEvent(trow, 'click', highlightRow);
    }//end while

    function highlightRow(gethighlight) { //now dual use - either set or get the highlighted row
        gethighlight = gethighlight === true;
        var t = trows.length;
        while (--t > -1) {
            trow = trows[t];
            if (gethighlight && trow.className === 'highlighted') { return t; }
            else if (!gethighlight) {
                if (trow !== this) { trow.className = 'normal'; }
                else if (this.className === 'normal') {
                    //rownum.value = t;
                }
                else {
                    //rownum.value = rownum.defaultValue;
                }
            }
        }//end while

        return gethighlight ? null : this.className = this.className === 'highlighted' ? 'normal' : 'highlighted';
    }//end function

    function movehighlight(way, e) {
        e.preventDefault && e.preventDefault();
        e.returnValue = false;
        var idx = highlightRow(true); //gets current index or null if none highlighted
        if (typeof idx === 'number') {//there was a highlighted row
            idx += way; //increment\decrement the index value
            if (idx && (nextrow = trows[idx])) { return highlightRow.apply(nextrow); } //index is > 0 and a row exists at that index
            else if (idx) { return highlightRow.apply(trows[1]); } //index is out of range high, go to first row
            return highlightRow.apply(trows[trows.length - 1]); //index is out of range low, go to last row
        }
        return highlightRow.apply(trows[way > 0 ? 1 : trows.length - 1]); //none was highlighted - go to 1st if down arrow, last if up arrow
    }//end function

    function processkey(e) {
        switch (e.keyCode) {
            case 38: {//up arrow
                return movehighlight(-1, e)
            }
            case 40: {//down arrow
                return movehighlight(1, e);
            }
            default: {
                return true;
            }
        }
    }//end function

    addEvent(document, 'keydown', processkey);
    addEvent(window, 'unload', function () { }); //optional, resets the page for browsers that remember the script state on back and forward buttons

}/* end function */)();//execute function and end script

No comments:

Post a Comment