parascus
parascus

Reputation: 1249

Elements of form is undefined in javascript

I try to set the focus on the first editable field in a form of my choice by the following code in javascript:

function setFocus( id) {
    var currentDialog = document.forms[id];

    for( i = 0; i < currentDialog.elements.length; i++) {
        if (!currentDialog.elements[i].disabled) {
            currentDialog.elements[i].focus();
            i = currentDialog.elements.length;
        }
    }
}

It finds the form but the elements seem to be undefined so the focus is not set. The weird thing is that I even get no error. In Firbug it shows me that elements is filled but the access to the property is not working.

I believe it is a small nasty error in my code but I can't find it. Has anybody of you an idea?

Upvotes: 1

Views: 3513

Answers (1)

Prasad
Prasad

Reputation: 701

for (var i = 0; i < currentDialog.elements.length; i++)

and not for (i = 0; i < currentDialog.elements.length; i++)

I think this was the mistake

Upvotes: 1

Related Questions