JavaScript Function to Automatically Focus Your Curser

Here’s a simple JavaScript function that iterates through all the forms on a page and drops the cursor in the first text or textarea input it finds. Not rocket science, but useful. If you’re building
an application, you probably include a header from each page, so
the way to use this function is to put it in your header (or better
yet, source or include it from your header), and call it onLoad.
That way, it will automatically work on any page in the application
with a form on it. If a page doesn’t have any forms, or you have
a form with no text or textarea inputs, the function does nothing.

function focusCursor()
{
for (var i = 0; i < document.forms.length; ++i)
{
var f = document.forms[i];
for (var j = 0; j < f.elements.length; ++j)
{
if (f.elements[j].type == 'text' ||
f.elements[j].type == 'textarea')
{
f.elements[j].focus();
return;
}
}
}
}