Posted by Jonathan N. Little on 10/12/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
[Back to original message]
|