I am using the getElementsByTagName("SPAN") to create an array of all the spans on a contact form. I am setting it up so that when the form fails validation, the span will display error text directly next to the input field to minimize confusion. I've been having problems, however, getting the span to function properly. I can get it to "alert" the span and its array key fine, however when I attempt to add content to it, I get "spans[...] has no properties" error. I have tried multiple different things, here's what I've got currently.
-
var elems = form.getElementsByTagName("SPAN");
-
var spans = new Array();
-
-
for (var i in elems) {
-
if (!elems[i].id) {
-
continue;
-
}
-
spans[elems[i].id] = elems[i];
-
}
-
-
for (var k in spans) {
-
alert("spans[" +k+ "] = " +spans[k]);
-
}
-
-
-
if (!isName(fName.value)) {
-
spans[fName].innerHTML = "Please enter a valid First Name.";
-
return false;
-
}
-
When it alerts, it alerts like this:
"spans[fName] = [object HTMLSpanElement]";
Edit: I meant "alert" in the title, not "echo" lol
PS, new to the forum, how do I display it as "javascript" code?