Connecting Tech Pros Worldwide Help | Site Map

yet another 'object has no properties' error

droesler@comcast.net
Guest
 
Posts: n/a
#1: Sep 28 '06
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

Martin Honnen
Guest
 
Posts: n/a
#2: Sep 28 '06

re: yet another 'object has no properties' error




droesler@comcast.net wrote:
Quote:
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.
Quote:
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.
Show us the function call so that we know the actual parameter values,
then show us the corresponding HTML markup for the form and the element.
Or post a URL where the problem occurs. Does the problem only occur
with Mozilla or other browsers too?

--

Martin Honnen
http://JavaScript.FAQTs.com/
droesler@comcast.net
Guest
 
Posts: n/a
#3: Sep 29 '06

re: yet another 'object has no properties' error



Martin Honnen wrote:
Quote:
droesler@comcast.net wrote:
>
Quote:
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.
>
Quote:
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.
>
Show us the function call so that we know the actual parameter values,
then show us the corresponding HTML markup for the form and the element.
Or post a URL where the problem occurs. Does the problem only occur
with Mozilla or other browsers too?
>
The HTML markup with the function call:
<a href="javascript:getEmail('officeInfo', 'officeEmail')"
title="Click here to select email addresses...">eMail</a>
<input type="text" name="officeEmail" value="$officeEmail"
tabindex="9">

The javascript function:
function getEmail(formName, fieldName) {
var email =
window.document.forms[formName].elements[fieldName].value;
if (email.length 0) {
email += ",";
}
var link = "/cgi-bin/ldapEmailPickList.pl?formName=" + formName +
"&fieldName=" + fieldName;
link += "&emailList=" + email;
window.open(link, "", "menubar, scrollbars, resizable, width=650,
height=600");
return;
}

droesler@comcast.net
Guest
 
Posts: n/a
#4: Sep 29 '06

re: yet another 'object has no properties' error



droes...@comcast.net wrote:
Quote:
Martin Honnen wrote:
Quote:
droesler@comcast.net wrote:
Quote:
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.
Quote:
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.
Show us the function call so that we know the actual parameter values,
then show us the corresponding HTML markup for the form and the element.
Or post a URL where the problem occurs. Does the problem only occur
with Mozilla or other browsers too?
>
The HTML markup with the function call:
<a href="javascript:getEmail('officeInfo', 'officeEmail')"
title="Click here to select email addresses...">eMail</a>
<input type="text" name="officeEmail" value="$officeEmail"
tabindex="9">
>
The javascript function:
function getEmail(formName, fieldName) {
var email =
window.document.forms[formName].elements[fieldName].value;
if (email.length 0) {
email += ",";
}
var link = "/cgi-bin/ldapEmailPickList.pl?formName=" + formName +
"&fieldName=" + fieldName;
link += "&emailList=" + email;
window.open(link, "", "menubar, scrollbars, resizable, width=650,
height=600");
return;
}
Meant to add that it occurs in both Mozilla and IE.

Closed Thread