View Single Post
  #1 (permalink)  
Old Jan 16th, 2008, 14:50
dsmithhfx dsmithhfx is offline
New Member
Join Date: Jan 2008
Location: Canada
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
[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
Reply With Quote