Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34319

Re: simple question

Path csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: simple question
Date Sun, 12 Nov 2017 14:22:38 +0000
Organization A noiseless patient Spider
Lines 63
Message-ID <87375jwp8x.fsf@bsb.me.uk> (permalink)
References <super70s-C3F170.07042612112017@reader02.eternal-september.org>
Mime-Version 1.0
Content-Type text/plain
Injection-Info reader02.eternal-september.org; posting-host="6990cf73bed5c4f34de9a73f4d41615b"; logging-data="2646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197rveUhruvAsmOfJjDTzLfkghM4AM0qpA="
Cancel-Lock sha1:WMZ8qQUNDZGgrsvukOHmnTr65Oc= sha1:HJ1kmysmu5TS6UN4kNn/b00cneY=
X-BSB-Auth 1.b8fe3d03ba16f64d2fa3.20171112142238GMT.87375jwp8x.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:34319

Show key headers only | View raw


super70s <super70s@super70s.invalid> writes:

> <head>
>
> <script language="JavaScript">
> <!-- Begin
> var msg = new Array();
> Stamp = new Date();
> today = Stamp.getDate();
>
> (messages)
> (messages)
> (messages)
> (messages)
>
> function writeTip() { 
> document.write(msg[today]);
> }
> //  End -->
> </script>
>
> </head>
> <body>
>
> <script>writeTip();</script>
>
> </body>
>
>
> Hi I have a simple question, if I had two of the above scripts on the 
> same page, how can I distinguish one from the other?

You can't, at least not in the way I think you mean.  I think you want
to be able to select two messages from two different arrays.  To do that
you should make the message array a parameter to your function.
(Personally, I'd do things a little differently but I want to suggest
minimal changes.)

So you have one script element with

  function writeTip(msgs) {
      document.write(msgs[new Date().getDate()];
  }

and then call it with different arrays from two other script elements
(I'll show only one):

  <script language=JavaScript>
      writeTip([
         "dummy",
         "Happy first!",
         ...
         "All over for this month."
      ]);
  </script>

No doubt I have lots of typos since this has not been machine checked.

Note how I have avoided variables where possible.  If you do need them
you should learn how to avoid them being "global".

-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

simple question super70s <super70s@super70s.invalid> - 2017-11-12 07:04 -0600
  Re: simple question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-12 14:22 +0000
    Re: simple question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-12 18:33 +0100
      Re: simple question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-12 20:28 +0000
        Re: simple question super70s <super70s@super70s.invalid> - 2017-11-12 15:11 -0600
          Re: simple question Andrew Poulos <ap_prog@hotmail.com> - 2017-11-13 13:26 +1100
        Re: simple question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-12 22:39 +0100
          Re: simple question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-13 01:20 +0000
            Re: simple question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-13 03:49 +0100
            Re: simple question Julio Di Egidio <julio@diegidio.name> - 2017-11-13 16:45 -0800

csiph-web