Length is Object???

T

Tyrone Slothrop

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;
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!
 
R

Richard Cornford

Tyrone Slothrop wrote:
var allfields = document.getElementsByTagName("input");
alert (allfields.length); // debug
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.
 
T

Tyrone Slothrop

Tyrone Slothrop wrote:


<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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top