Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Correct syntax for loop

1 view
Skip to first unread message

wildred

unread,
Sep 18, 2009, 9:16:34 PM9/18/09
to
I have 3 layers on a page. When I click one I want to hide all 3 layers. The
function below calls another function (it works correctly) that hides them
all. The names of the layers are - layer1, layer2 and layer3. But my 'for
loop' syntax below is not working. What is the proper syntax to hide the
layers? Thanks a lot.

function hideAll() {
var i=0;
for (i=0;i<=2;i++)
{
HideContent('layer') + i;
}}

L.@canberra Trevor Lawrence

unread,
Sep 19, 2009, 12:12:56 AM9/19/09
to
"wildred" <s...@fg.org> wrote in message
news:412CB9D6-2E02-4467...@microsoft.com...

Wouldn't this execute these statements:
HideContent('layer') + 0;
HideContent('layer') + 1;
HideContent('layer') + 2;
?

Not having seen HideContent, I would have thought that you would want:
HideContent('layer' + 1);
HideContent('layer' + 2);
HideContent('layer' + 3);

If so, I think that the code should read:
function hideAll() {
for (var i=1;i<=3;i++)
{ HideContent('layer' + i); }
}

--
Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org


wildred

unread,
Sep 19, 2009, 3:51:03 AM9/19/09
to
Thanks a lot, Trevor. Works great. This will really help my page
programming.


<Trevor L.@Canberra> wrote in message
news:uIpe29N...@TK2MSFTNGP02.phx.gbl...

Andrey Pashentsev

unread,
Nov 18, 2009, 1:31:16 PM11/18/09
to
I think, you call HideContent function in wrong way. :)
Try this code.
So, hideAll calls HideContent 3 times and pass 3 params in such order:
'layer1', 'layer2' and 'layer3'.

function hideAll() {
for (var i=1;i<=3;i++)
{
HideContent('layer' + i);
}
}


"wildred" <s...@fg.org> сообщил/сообщила в новостях следующее:
news:412CB9D6-2E02-4467...@microsoft.com...

Evertjan.

unread,
Nov 18, 2009, 2:04:01 PM11/18/09
to
Andrey Pashentsev wrote on 18 nov 2009 in
microsoft.public.scripting.jscript:

> I think, you call HideContent function in wrong way. :)
> Try this code.
> So, hideAll calls HideContent 3 times and pass 3 params in such order:
> 'layer1', 'layer2' and 'layer3'.
>
> function hideAll() {
> for (var i=1;i<=3;i++)
> {
> HideContent('layer' + i);
> }
>}

For small numbers you might [in this NG] be forgiven for not doing a loop:

function hideAll() {
HideContent('layer1');
HideContent('layer2');
HideContent('layer3');
};

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

0 new messages