473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Element has no Properties (but will alert() properties)

tj111
12
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.
Expand|Select|Wrap|Line Numbers
  1.     var elems = form.getElementsByTagName("SPAN");
  2.     var spans = new Array();
  3.  
  4.     for (var i in elems) {
  5.         if (!elems[i].id) {
  6.             continue;
  7.         }
  8.         spans[elems[i].id] = elems[i];
  9.     }
  10.  
  11.     for (var k in spans) {
  12.         alert("spans[" +k+ "] = " +spans[k]);
  13.     }
  14.  
  15.  
  16.     if (!isName(fName.value)) {
  17.         spans[fName].innerHTML = "Please enter a valid First Name.";
  18.         return false;
  19.     }
  20.  
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?
Aug 21 '07 #1
2 2944
epots9
1,351 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1.     var elems = form.getElementsByTagName("SPAN");
  2.     var spans = new Array();
  3.  
  4.     for (var i in elems) {
  5.         if (!elems[i].id) {
  6.             continue;
  7.         }
  8.         spans[elems[i].id] = elems[i];
  9.     }
  10.  
  11.     for (var k in spans) {
  12.         alert("spans[" +k+ "] = " +spans[k]);
  13.     }
  14.  
  15.  
  16.     if (!isName(fName.value)) {
  17.         spans[fName].innerHTML = "Please enter a valid First Name.";
  18.         return false;
  19.     }
  20.  
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?
the problem might be in how you move the spans from one array to another. why are u moving your data from one array to another? elems is an array (nodeList) of all your span elements. you can go through them one by one and have access to all its attributes.

to use javascript code tag:
[ code=javascript][/code] (without spaces)
Aug 21 '07 #2
pbmods
5,821 Expert 4TB
Heya, TJ. Welcome to TSDN!

Fixed the title for you.

On line 17 of the code you posted, did you mean this instead?
Expand|Select|Wrap|Line Numbers
  1. // ----------¬
  2. spans[fName.value].innerHTML = "Please enter a valid First Name.";
  3.  
And to nitpick, the correct syntax for line 2 is:
Expand|Select|Wrap|Line Numbers
  1. var spans = {};
  2.  
(using curly braces {})

Since you're actually creating a generic object instead of an array.
Aug 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: katended | last post by:
Help plz, i dont know but i have this project developed in vb6 on win2kpro OS and its just 3.35MB, it complies properly-without any errors. But will never package the app when i use the packaging and...
4
by: james | last post by:
I cannot get my UserControl's browsable properties to show up in the designer properties panel. I have then public virtual bool TestProp { {get return testProp; } set { testProp = value; } } ...
9
by: Dimsion | last post by:
Hi, How do i expose all my forms and it controls to other form in the project? I want to be able to add a form and some control on it, this then be available to all other forms. form1 click...
1
by: bhavanirayala | last post by:
Hi, I am new to perl.Basically I am from java.Now I am getting error while i reading the configuration parameters in perl. #!/usr/bin/perl use Config::Properties; # reading... open...
5
by: Jon Pope | last post by:
I've got a class which contains properties. I can supply this class to the Properties control, and it will properly display the properties and allow the user to edit them, etc. I would like to be...
6
by: divina11 | last post by:
I'm testing the following script and it's not alerting the second alert, what is the reason for this? I'm getting a blank page. The first alert("Hi") works fine. <script> function Book() {...
1
by: MMAS | last post by:
I've seen a similar post about this problem but still cannot find an automated solution. Below is the code I'm using to create a website (for IIS 6.0) via C#. once the site is created, it will not...
7
by: bbobely | last post by:
Hi, I've built a sequence that works thusly: User chooses a value from a combo box. This causes a query to run displaying records with a field value matching the combo box in subform 1. Then, the...
3
by: Chocolade | last post by:
Im using win32_printer and im adding to listbox1 a list of the printer properties. but then when im scrolling down in the listbox1 and getting to the last property i see the list of properties start...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.