yet another 'object has no properties' error

Giganews Newsgroups
Subject: yet another 'object has no properties' error
Posted by:  droesl…@comcast.net
Date: 27 Sep 2006

I have a function that receives a form name and field name.

someFunc(formName, fieldName) {
  var fieldVal = document.forms[formName].elements[fieldName].value;
  [snip]
}

This triggers the 'has no properties error.  An alert message shows the
correct values are being passed in.  If I hardcode
  var fieldVal = document.realFormName.realFieldName.value;
no error is generated and fieldVal has the value of the input field.

An alert(document.forms.length) displays 1, which is what I would
expect.  It seems if I try to access some part of the document through
variables in javascript errors are generated.  If I hard code document
object names in the javascript then the javascript functions as
expected.

The generated document passes the w3c validator test, although that
doesn't look at all of the sourced javascript files; and the Mozilla
JavaScript console shows no errors until the above function is called.

How can I troubleshoot this problem?

Thanks

Dennis

Replies