Forums

Automatically Focus Search Box

commitmenttitle 09 Apr, 2010
I added a search field per the instructions on this forum. I want the cursor to automatically focus the field when the page is loaded. How would I do this?

My usual js for this:
<script language='javascript' type='text/javascript'>
function SetFocus()
{
    // safety check, make sure its a post 1999 browser
    if (!document.getElementById)
    {
        return;
    }

    var txtMyInputBoxElement = document.getElementById("my_search_box");

    if (txtMyInputBoxElement != null)
    {
        txtMyInputBoxElement.focus();
    }
}
SetFocus();
</script>

is not working.

The form is password protected, but I can provide access if necessary.
This topic is locked and no more replies can be posted.