By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,931 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

yet another 'object has no properties' error

P: n/a
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

Sep 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


dr******@comcast.net wrote:
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.
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/
Sep 28 '06 #2

P: n/a

Martin Honnen wrote:
dr******@comcast.net wrote:
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.
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;
}

Sep 29 '06 #3

P: n/a

droes...@comcast.net wrote:
Martin Honnen wrote:
dr******@comcast.net wrote:
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.
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.

Sep 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.