Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34319
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: simple question |
| Date | 2017-11-12 14:22 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87375jwp8x.fsf@bsb.me.uk> (permalink) |
| References | <super70s-C3F170.07042612112017@reader02.eternal-september.org> |
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
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