Connecting Tech Pros Worldwide Forums | Help | Site Map

What am I doing wrong here. Simple statement. Novice Question.

Paul
Guest
 
Posts: n/a
#1: Jul 23 '05
HI! I get an error with this code.

<SCRIPT language="JavaScript">
If (ifp==""){
ifp="default.htm"}
//--></SCRIPT>

Basicly I want my iframe to have a default page if the user enters in
directly. so I need a way doing this. so I check to see if the ifp value is
null and if so then assign it a value. is this correct?


Thanks in advance :)

Paul



Joe Fawcett
Guest
 
Posts: n/a
#2: Jul 23 '05

re: What am I doing wrong here. Simple statement. Novice Question.


"Paul" <paul.dallaire@sympatico.ca> wrote in message
news:uLpEe.7414$Qi4.983731@news20.bellglobal.com.. .[color=blue]
> HI! I get an error with this code.
>
> <SCRIPT language="JavaScript">
> If (ifp==""){
> ifp="default.htm"}
> //--></SCRIPT>
>
> Basicly I want my iframe to have a default page if the user enters in
> directly. so I need a way doing this. so I check to see if the ifp value is
> null and if so then assign it a value. is this correct?
>
>
> Thanks in advance :)
>
> Paul[/color]
As you don't state the error I may wrong but if, as I expect, it is "object
expected" then it's because you have a capital "I" in "If" which should be
lowercase:

if (ifp == "")
{
ifp = "default.htm";
}

In general all JavaScript keywords start with lowercase letters, built-in
objects such as "String" are one such exception, and usually if two or more
words are concatenated all but the first have an uppercase first letter, e.g
"toLowerCase". An exception to this are the operators such as "typeof".
--
As a side point, although in this instance the syntax is the same, Java and
JavaScript are two different beasts and I suggest restricting your choice of
groups to the relevant ones.

Joe (MVP)

https://mvp.support.microsoft.com/pr...8-8741D22D17A5



Richard Cornford
Guest
 
Posts: n/a
#3: Jul 23 '05

re: What am I doing wrong here. Simple statement. Novice Question.


Paul wrote:[color=blue]
> <SCRIPT language="JavaScript">
> If (ifp==""){
> ifp="default.htm"}
> //--></SCRIPT>[/color]
<snip>[color=blue]
> ... . so I check to see if the ifp
> value is null ...[/color]
<snip>

The algorithm for the type-converting comparison operator - == - (ECMA
262 3rd edition; section 11.9.3) does not allow any string value
(including the empty string) to equal null. So whatever you are
attempting you are not seeing if ifp is null.

Richard.


Paul
Guest
 
Posts: n/a
#4: Jul 23 '05

re: What am I doing wrong here. Simple statement. Novice Question.


HI! thanks, I saw that little one after I posted it. but there is still a
problem. and the other post answered that one.

Do you know of another way to do it. ( other than converting the string and
then back again )?

Thanks in advance :)

Paul
"Joe Fawcett" <joefawcett@newsgroups.nospam> wrote in message
news:uETXwC5jFHA.1044@tk2msftngp13.phx.gbl...[color=blue]
> "Paul" <paul.dallaire@sympatico.ca> wrote in message
> news:uLpEe.7414$Qi4.983731@news20.bellglobal.com.. .[color=green]
>> HI! I get an error with this code.
>>
>> <SCRIPT language="JavaScript">
>> If (ifp==""){
>> ifp="default.htm"}
>> //--></SCRIPT>
>>
>> Basicly I want my iframe to have a default page if the user enters in
>> directly. so I need a way doing this. so I check to see if the ifp value
>> is null and if so then assign it a value. is this correct?
>>
>>
>> Thanks in advance :)
>>
>> Paul[/color]
> As you don't state the error I may wrong but if, as I expect, it is
> "object expected" then it's because you have a capital "I" in "If" which
> should be lowercase:
>
> if (ifp == "")
> {
> ifp = "default.htm";
> }
>
> In general all JavaScript keywords start with lowercase letters, built-in
> objects such as "String" are one such exception, and usually if two or
> more words are concatenated all but the first have an uppercase first
> letter, e.g "toLowerCase". An exception to this are the operators such as
> "typeof".
> --
> As a side point, although in this instance the syntax is the same, Java
> and JavaScript are two different beasts and I suggest restricting your
> choice of groups to the relevant ones.
>
> Joe (MVP)
>
> https://mvp.support.microsoft.com/pr...8-8741D22D17A5
>
>
>[/color]


Joe Fawcett
Guest
 
Posts: n/a
#5: Jul 24 '05

re: What am I doing wrong here. Simple statement. Novice Question.


"Paul" <paul.dallaire@sympatico.ca> wrote in message
news:ehgXHG7jFHA.572@TK2MSFTNGP15.phx.gbl...[color=blue]
> HI! thanks, I saw that little one after I posted it. but there is still a
> problem. and the other post answered that one.
>
> Do you know of another way to do it. ( other than converting the string and
> then back again )?
>
> Thanks in advance :)
>
> Paul[/color]
I'm not sure, if you want to test for null or empty string the have:
if (!ifp)
{
//ifp is null or empty
}


--

Joe (MVP)

https://mvp.support.microsoft.com/pr...8-8741D22D17A5


akarl
Guest
 
Posts: n/a
#6: Aug 9 '05

re: What am I doing wrong here. Simple statement. Novice Question.


Paul wrote:[color=blue]
> HI! I get an error with this code.
>
> <SCRIPT language="JavaScript">
> If (ifp==""){
> ifp="default.htm"}
> //--></SCRIPT>
>
> Basicly I want my iframe to have a default page if the user enters in
> directly. so I need a way doing this. so I check to see if the ifp value is
> null and if so then assign it a value. is this correct?[/color]

comp.lang.javascript
Trevor L.
Guest
 
Posts: n/a
#7: Aug 9 '05

re: What am I doing wrong here. Simple statement. Novice Question.


Hmm!

There have been a few posts on this topic (or related), including some I
have taken part in

One spelt out the different between:
a null string, tested by 'if (string == null)'
an empty string, tested by 'if (string == "")'
and
a string comprising a space, tested by 'if (string == " ")'

Your test is for an empty string. Is this what it should be?

You are testing if (ifp == ..). I have not used iframes, so I don't know
whether this is the correct thing to be testing. Others may answer this.

With frames, I use this code
if (parent.location.href == window.location.href)
parent.location.href = "index.html"

I would need to experiment to see what works with iframes. (Maybe I should,
to add to my knowledge !)
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

akarl wrote:[color=blue]
> Paul wrote:[color=green]
>> HI! I get an error with this code.
>>
>> <SCRIPT language="JavaScript">
>> If (ifp==""){
>> ifp="default.htm"}
>> //--></SCRIPT>
>>
>> Basicly I want my iframe to have a default page if the user enters in
>> directly. so I need a way doing this. so I check to see if the ifp
>> value is null and if so then assign it a value. is this correct?[/color]
>
> comp.lang.javascript[/color]


Closed Thread