J
JJA
I'm trying to use document.getElementByID inside a function where the
ID is passed as an argument. I get the same error ("Element has no
properties") on the same statement inside the commonCheck function
with either MS IE 6.0 or Mozilla Firefox 0.9. Comments below indicate
that if I hardcode an element ID I can avoid the error, but I
obviously want to parameterize it. Here are some snippets of my code:
-----snippet 1-------------------------------------------------------
<form method="POST" action="UserProfileMaint.htm"
onSubmit="return validateTelnr ("txtPhone", "msgPhone", true);">
<p> </p>
<p> </p>
<table id="tblMain" border="0" width="100%">
<tr>
<td width="25%"> </td>
<td width="25%">Phone</td>
<td width="25%"><input type="text" name="txtPhone" id="txtPhone"
size="20"></td>
<td width="25%"><input type="hidden" name="msgPhone"
id="msgPhone"></td>
</tr>
-----snippet 2-------------------------------------------------------
function validateTelnr (vfld, // element to be validated
ifld, // id of element to receive
info/error msg
reqd) // true if required
{
var stat = commonCheck (vfld, ifld, reqd);
-----snippet 3-------------------------------------------------------
function commonCheck (vfld, // element to be validated
ifld, // id of element to receive
info/error msg
reqd) // true if required
{
if (!document.getElementById)
return true; // not available on this browser - leave validation
to the server
var elem = document.getElementById(ifld); // this will fail on next
stmt
//var elem = document.getElementById("txtPhone"); //COMMENTED OUT:
this works
if (!elem.firstChild) //------> fails here with msg "elem has no
properties"
return true; // not available on this browser
if (elem.firstChild.nodeType != node_text)
return true; // ifld is wrong type of node
if (emptyString.test(vfld.value)) {
if (reqd) {
msg (ifld, "error", "ERROR: required");
vfld.focus();
return false;
}
ID is passed as an argument. I get the same error ("Element has no
properties") on the same statement inside the commonCheck function
with either MS IE 6.0 or Mozilla Firefox 0.9. Comments below indicate
that if I hardcode an element ID I can avoid the error, but I
obviously want to parameterize it. Here are some snippets of my code:
-----snippet 1-------------------------------------------------------
<form method="POST" action="UserProfileMaint.htm"
onSubmit="return validateTelnr ("txtPhone", "msgPhone", true);">
<p> </p>
<p> </p>
<table id="tblMain" border="0" width="100%">
<tr>
<td width="25%"> </td>
<td width="25%">Phone</td>
<td width="25%"><input type="text" name="txtPhone" id="txtPhone"
size="20"></td>
<td width="25%"><input type="hidden" name="msgPhone"
id="msgPhone"></td>
</tr>
-----snippet 2-------------------------------------------------------
function validateTelnr (vfld, // element to be validated
ifld, // id of element to receive
info/error msg
reqd) // true if required
{
var stat = commonCheck (vfld, ifld, reqd);
-----snippet 3-------------------------------------------------------
function commonCheck (vfld, // element to be validated
ifld, // id of element to receive
info/error msg
reqd) // true if required
{
if (!document.getElementById)
return true; // not available on this browser - leave validation
to the server
var elem = document.getElementById(ifld); // this will fail on next
stmt
//var elem = document.getElementById("txtPhone"); //COMMENTED OUT:
this works
if (!elem.firstChild) //------> fails here with msg "elem has no
properties"
return true; // not available on this browser
if (elem.firstChild.nodeType != node_text)
return true; // ifld is wrong type of node
if (emptyString.test(vfld.value)) {
if (reqd) {
msg (ifld, "error", "ERROR: required");
vfld.focus();
return false;
}