Javascript/JQuery Return focus to specific element in grid after programmatic click

525 views Asked by At

In Enterprise Portal (essentially sharepoint) we're attempting to automatically fire the "click" of a button whenever a td loses focus, and then return focus to the cell of the table we left. The idea is that we want the user to be able to continuously enter data without having to click that button every time.

The problem is, I don't know how to specify a specific cell within the table to return to, so it just returns to the first cell. I've read in several places that this is either very difficult or impossible without things like SlickGrid. Can anyone help me do this in straight up Javascript/Jquery?

The code I have so far looks like this:

<script>

$jQ(window).load(function refreshSummary() {
    var activeElement;
    $jQ("td").focus(function () {
        activeElement = document.activeElement;
    });
    $jQ("td").focusout(function () {
        var refreshLink = "ctl00_ctl00_m_g_78a9aecd_0fef_4b43_a2ff_45942fe92ea0_ctl01_ctl04_RefreshLink";
        document.getElementById(refreshLink).click();
        document.getelementbyid(activeelement).focus();
    });
});
</script>
1

There are 1 answers

1
Evan On BEST ANSWER

Don't you want to just focus back on the element after click on focusout?

$jQ(window).load(function refreshSummary() {
    var activeElement;
    $jQ("td").focus(function () {
        activeElement = document.activeElement;
    });
    $jQ("td").focusout(function () {
        var refreshLink = "ctl00_ctl00_m_g_78a9aecd_0fef_4b43_a2ff_45942fe92ea0_ctl01_ctl04_RefreshLink";

        document.getElementById(refreshLink).click();
        $(this).focus();
    });
});