Javascript – MooTools: Set focus on click

asp.netjavascriptmootools

I've got an ASP.NET control that contains a checkbox. I want the focus to remain on this checkbox when it's clicked. Here's what I'm using:

<script type="text/javascript">
    window.addEvent("domready", function() {

        var acceptCheckId = $("<%= this.accept.ClientID %>").getElement("input");

        acceptCheckId.addEvent("click", function() {
            acceptCheckId.focus();
        });

    });
</script>

I can get the checkbox element into the acceptCheckId variable okay, but when I click on it, the focus doesn't change. What gives?

If I add an alert in, the alert never fires:

    acceptCheckId.addEvent("click", function() {
        alert("foobar");
        acceptCheckId.focus();
    });

Best Solution

What does your output HTML look like? it's impossible to say what's wrong w/ the code w/o knowing how your <% %> content is written.

<script type="text/javascript">
window.addEvent("domready", function() {

    var acceptCheckId = $("<%= this.accept.ClientID %>").getElement("input"); 
    // $('elementId').getChildren('input');
    // You can't put an entire element in there                                                 

    acceptCheckId.addEvent("click", function() {
        acceptCheckId.focus();
    });

});
</script>