You are here: Re: JavaScript problem « HTML « IT news, forums, messages
Re: JavaScript problem

Posted by Jonathan N. Little on 11/13/98 11:25

Morgan wrote:
> Hi,
> I know this is a HTML group but most of you appear to be JavaScript
> programmers too, So here is what is likely a stupid question for you.
> ->
> I'm just begining JavaScript and am running into this problem:
>
> function sayHello(arg1)
> {
> if(arg1 =="" || arg1==(typeof arg1=="undefined"))
> {
> alert("Enter a value.");
> }
> else
> {
> alert("Hi "+arg1);
> }
> }
> sayHello();
>
> Now I pass something to the function sayHello by calling it with
> sayHello("Morgan");
> for example. Works fine.
> However my if conditional for checking whether the passed value to the
> arguement is ok is screwed up. I am checking for a undefined value or
> an emphty string.
> Why can't I check for whether the argument is undefined? I keeping
> coming up with an alert of Hi undefined.
> Thanks for any help in advance. :)
>

fix your arg test

function sayHello(arg1)
{
if(arg1 =="" || typeof(arg1)=="undefined")
{
alert("Enter a value.");
}
else
{
alert("Hi "+arg1);
}
}


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация