Web Design and Development Forums

[SOLVED] Syntax problem -- object has no properties

This is a discussion on "[SOLVED] Syntax problem -- object has no properties" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Syntax problem -- object has no properties are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Jan 16th, 2008, 14:50   #1 (permalink)
New Member
 
Join Date: Jan 2008
Location: Canada
Posts: 4
[SOLVED] Syntax problem -- object has no properties

I just realized I posted this here instead of the javascript folder... can a moderator move it there, by any chance? thanks!

Hi,

I've got a script that works, but is returning an error in Firebug:
HTML: Select all
var thirdpngs = document.getElementsByName('last');

function showit(){
    for (iName in thirdpngs){
    thirdpngs[iName].style.display = 'inline';    
    }   
}

function hideit(){
    for (iName in thirdpngs){
    thirdpngs[iName].style.display = 'none';    
    }   
}
The error is "thirdpngs[iName].style has no properties"

I'm puzzled because:
HTML: Select all
var thirdpngs = document.getElementsByName('last');

function showit(){
    thirdpngs[0].style.display = 'inline'; 
    thirdpngs[1].style.display = 'inline'; 
    thirdpngs[2].style.display = 'inline'; 
}

function hideit(){
    thirdpngs[0].style.display = 'none'; 
    thirdpngs[1].style.display = 'none'; 
    thirdpngs[2].style.display = 'none'; 
}
doesn't return any errors.


Fixed:
HTML: Select all
var thirdpngs = document.getElementsByName('last');
function showit(){
    for (var i = 0; i <= 2; i++) {
        thirdpngs[i].style.display = 'inline';
    }
}

function hideit(){
    for (var i = 0; i <= 2; i++) {
        thirdpngs[i].style.display = 'none';
    }
}
-------------
[at least in Firefox; script doesn't work in IE7...)

Last edited by c010depunkk; Jan 19th, 2008 at 13:22. Reason: please use [HTML] tags when posting HTML
dsmithhfx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 18th, 2008, 10:13   #2 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Syntax problem -- object has no properties

"Object has no properties" basically happened because you were trying to use an element that didn't exist (null).

To avoid the problem, this line:
for (var i = 0; i <= 2; i++) {

should actually be written like this:
for (var i = 0; i < thirdpngs.length; i++) {

...so it will work when you have 1, 2, 3 or 7 million items in the array.
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 18th, 2008, 12:53   #3 (permalink)
New Member
 
Join Date: Jan 2008
Location: Canada
Posts: 4
Re: Syntax problem -- object has no properties

see "Fixed" ^^^. The error is/was no more...
dsmithhfx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 18th, 2008, 13:57   #4 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Syntax problem -- object has no properties

read my post and you will see that, although you have it working, the proper way to code it will avoid this problem in the future. it's good practice not to hard code the length of arrays - the whole purpose is for them to be dynamic...
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 18th, 2008, 14:06   #5 (permalink)
New Member
 
Join Date: Jan 2008
Location: Canada
Posts: 4
Re: Syntax problem -- object has no properties

dsmithhfx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 19th, 2008, 12:55   #6 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
Re: [SOLVED] Syntax problem -- object has no properties

Moved and Solved.
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 19th, 2008, 19:30   #7 (permalink)
New Member
 
Join Date: Jan 2008
Location: Canada
Posts: 4
Re: [SOLVED] Syntax problem -- object has no properties

Thanks Alex.
dsmithhfx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] error in SQL syntax but where it all looks fine to me Andrew1986 MySQL 3 Nov 28th, 2007 01:21
[SOLVED] Field validation and changing display properties... c_martini JavaScript Forum 12 Sep 25th, 2007 11:27
Syntax problem in PHP table creation masonbarge MySQL 4 Jul 13th, 2006 22:27
Mysql syntax problem... ktsirig MySQL 1 Jan 6th, 2006 15:51
IIS (DB/Object Readonly) problem spinal007 MSSQL & Access 2 Oct 19th, 2004 18:35



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 05:01.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59