[Javascript] javascript and id's

Anthony Ettinger apwebdesign at yahoo.com
Tue Oct 4 12:36:59 CDT 2005



--- Paul Novitski <paul at novitskisoftware.com> wrote:

> At 10:20 AM 10/4/2005, Anthony Ettinger wrote:
> >Yes, this is what I came up with:
> >
> >function changeAttrib(id, attrib, newValue)
> >{
> >         var elemObj = document.getElementById(id);
> >         elemObj.setAttribute(attrib, newValue);
> >
> >         return true;
> >}
> 
> 
> Looks good.  But why are you returning true?  You
> don't have to, 
> especially in a case like this where your function
> ALWAYS returns the 
> same value.  Unlike some other languages (VBscript,
> for example), 
> JavaScript lets you treat a function like a sub
> call, that is:
> 
>          x = doSomething(y);
> 
> or simply:
> 
>          doSomething(y);

Agreed, I wasn't sure what the standard was. I've
heard people say "always return true", and others only
if it's returning a value should you use return.

I've shortened the function:

function changeAttrib(id, attrib, newValue)
{
	document.getElementById(id).setAttribute(attrib,
newValue);
}



Anthony Ettinger
ph: (408) 656-2473
blog: http://www.chovy.com


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com



More information about the Javascript mailing list