Q:

For loop returns undefined variable

var formobj = document.h1;
for (var j = 0; j < formobj.elements.length; j++) {
    if (formobj.elements[j].type == "radiobutton" && formobj.elements[j].checked) {
        var wholebase = formobj.elements[j].value;
    }
}

Later in the script, the variable is set to the inner html of a div and is labeled as undefined. Is there a flaw in my for loop?

A:

There is no type radiobutton, I think you want type == 'radio'.

