473,402 Members | 2,053 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,402 software developers and data experts.

javascript: variable has no properties

1
im trying to iterate thru form elements and pull out the ones with "note" in their name. getting "elementName has no properties" with the following code, and i don't understand why? any help is greatly appreciated. thx!

Expand|Select|Wrap|Line Numbers
  1. Code:
  2.  
  3. function saveNotes(){ 
  4. var elementName=''; 
  5. var isNote=''; 
  6. for(i=0; i<document.formNotes.elements.length; i++){ elementName=document.formNotes.elements[i].name; isNote=elementName.indexOf('note'); 
  7. if (isNote!=-1) {
  8.  alert('its a note!'); 
  9. }
  10. }
  11. }
changing "elementName=document.formNotes.elements[i].name;" to "alert(document.formNotes.elements[i].name);" gives me the name. why won't it transfer the name of the element to the variable?

thanks!
Jun 21 '06 #1
2 5827
acoder
16,027 Expert Mod 8TB
Without the HTML it'd be difficult to say, but the code would work with, for example:
[html]<form name="formNotes">
<input type="text" name="notes">
<input type="button" onclick="saveNotes()" value="Save">
</form>[/html]
May 1 '08 #2
mrhoo
428 256MB
Change this line-
elementName=document.formNotes.elements[i].name;
to this:
elementName=document.formNotes.elements[i].name || '';

Chances are your form has a fieldset or some other member that is counted as a form element but returns undefined for the name attribute.

Give your undefined's the empty string, which will return -1 for any indexOf call.
May 1 '08 #3

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

Similar topics

3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
1
by: Neil Cherry | last post by:
What I'm basically trying to do is call a Java applet public method ( public void setInterval(int i) {...} ) from javascript in Firfox 1.0.7. I've not done this before but most of google agrees...
3
by: Bandaar | last post by:
Hello, I have a difficult task I believe. I have tcl code that opens a webpage, then via execScript commands calls javascript code to play audio files for my js object player. The problem is...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
4
by: iamthebest | last post by:
Hello, I am trying to call a javscript function from c#. But it is not getting called. The error comes up saying funtionname is not defined even though it is defined and visible in page source. ...
1
by: manojuniverse | last post by:
Hi can any body help me in knowing in javscript on client side whether session has expired or not. Plz help me. Thanks in advance.
4
by: Cirene | last post by:
I have javascript code that does an alert on a public asp.net var... alert("<%=strMessage%>"); The code runs whenever my ajax related code completes. I declared the public var like this......
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.