tags:

views:

67

answers:

1
function focus(element) {
    document.form.element.focus();
}

I want to have a function to focus on an input box, but it seems I can't do that. Is there a better way to do this?

+6  A: 

If you're passing element directly to the function, call focus directly on that.

function focus(element) {
    element.focus();
}

If you're just passing the name of the element to the function, then ..

function focus(element) {
    document.form[element].focus();
}
Matt