Connecting Tech Pros Worldwide Help | Site Map

Length is Object???

Tyrone Slothrop
Guest
 
Posts: n/a
#1: Aug 19 '06
I am running a bit of JS to highlight text inputs onFocus in IE. It
seems to be working on all of the forms on the site except one. The
debug code in the script displays the number of input elements in an
alert. On the page where it does not work, the alert is "[object]".

Here is the script:

function initHighlight() {
if (!document.getElementsByTagName){ return; }
var allfields = document.getElementsByTagName("input");
alert (allfields.length); // debug
for (var i=0; i<allfields.length; i++){
var field = allfields[i];
var attr = field.getAttribute("type");
if (attr == "text" || attr == "password") {
field.onfocus = function () {
this.className = 'highlightActiveField';
}
field.onblur = function () {this.className =
'highlightInactiveField';}
}
}
}

function addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function'){ window.onload = func; }
else { window.onload = function() { oldonload(); func(); } }
}

var isIE = navigator.appName.indexOf("Microsoft") != -1;
if (isIE) { addLoadEvent(initHighlight); }

Unfortunately, I cannot reveal the URL of the page (contractural
restrictions).

Under what conditions would IE believe that the length of input fields
is an object, not a number? I have run the page through two
different validators and there are no errors.

TIA!
Richard Cornford
Guest
 
Posts: n/a
#2: Aug 19 '06

re: Length is Object???


Tyrone Slothrop wrote:
<snip>
Quote:
var allfields = document.getElementsByTagName("input");
alert (allfields.length); // debug
<snip>
Quote:
Under what conditions would IE believe that the length of
input fields is an object, not a number?
<snip>

Whenever the NAME and/or ID attribute of an IPUT element was "length".

Richard.


Tyrone Slothrop
Guest
 
Posts: n/a
#3: Aug 20 '06

re: Length is Object???


On Sat, 19 Aug 2006 22:36:58 +0100, "Richard Cornford"
<Richard@litotes.demon.co.ukwrote:
Quote:
>Tyrone Slothrop wrote:
><snip>
Quote:
> var allfields = document.getElementsByTagName("input");
> alert (allfields.length); // debug
><snip>
Quote:
>Under what conditions would IE believe that the length of
>input fields is an object, not a number?
><snip>
>
>Whenever the NAME and/or ID attribute of an IPUT element was "length".
>
>Richard.
>
<slaps forehead Well, wouldn't you know there is an input called
length in that form. Renemed it and it works.

Thanks!
Closed Thread