Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / May 2006



Tip: Looking for answers? Try searching our database.

Random scrolling text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sven.daems@gmail.com - 30 May 2006 20:42 GMT
Hy

I want to add a sort of news service to my site.  I've a number of
messages, wich I want to be shown in a <marquee> tag. I've found a
simple scrit that generates an random message (wich I've putted in an
array) and the message is shown in an marquee tag. The problem is that
for changing  the message, a reload of the page is required. Isn't
there a way to reload the message? Or every time the marquee tag shows
a message, it will be a differrent message? Or perhaps not using the
marquee tag, but another way to scroll text trough a page?

Thanxs in advance
Sven Daems

<SCRIPT LANGUAGE = "JavaScript">

    // The Array Function

    function makeArray(len) {
       for (var i = 0; i < len; i++) this[i] = null;
    this.length = len;
    }

    // This is where the array of text/images/sounds is created.

    ideas = new makeArray(22);
    ideas[0] = "Message1"
    .....
    ideas[21] = "Message22"

    // The random number generator.

    function rand(n) {
    seed = (0x015a4e35 * seed) % 0x7fffffff;
    return (seed >> 16) % n;
    }

    var now = new Date()
    var seed = now.getTime() % 0xffffffff

    </SCRIPT>
</head>
--------------------------------------------
<body background="images/midden_top.jpg">
<marquee>
    <SCRIPT LANGUAGE = "JavaScript">

    // Where you place this is where the random object will be displayed.

    document.write(ideas[rand(ideas.length)])   

</SCRIPT>
</marquee>
RobG - 31 May 2006 00:13 GMT
> Hy
>
> I want to add a sort of news service to my site.  I've a number of
> messages, wich I want to be shown in a <marquee> tag. I've found a

The marquee element is not part of the W3C HTML 4 specification, it is
supported in varying degrees by many browsers but it is likely that
there are some that don't support it at all.

MozDev:
<URL:http://developer.mozilla.org/en/docs/HTML:Element:marquee>

MSDN:
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/marquee.asp>

> simple scrit that generates an random message (wich I've putted in an
> array) and the message is shown in an marquee tag. The problem is that
> for changing  the message, a reload of the page is required. Isn't
> there a way to reload the message? Or every time the marquee tag shows
> a message, it will be a differrent message? Or perhaps not using the
> marquee tag, but another way to scroll text trough a page?

The link above will tell you most of that, but again, support is likely
to be patchy.

 > <SCRIPT LANGUAGE = "JavaScript">

The language attribute is deprecated, type is required:

  <script type="text/javascript">

>     // The Array Function
>
>     function makeArray(len) {
>        for (var i = 0; i < len; i++) this[i] = null;
>     this.length = len;
>     }

That is a totally useless function.  Use the in-built JavaScript array
object.

>     // This is where the array of text/images/sounds is created.
>
>     ideas = new makeArray(22);
>     ideas[0] = "Message1"
>     .....
>     ideas[21] = "Message22"

Seems much easier to use:

    ideas = [
             "Message 1",
             "Message 2",
             "Message 3",
              ...
              "Message n"
             ];

>     // The random number generator.
>
>     function rand(n) {
>     seed = (0x015a4e35 * seed) % 0x7fffffff;
>     return (seed >> 16) % n;
>     }

Why not use Math.random?  For this exercise, it doesn't seem that a
separate random number function is required anyway.  A 'get next random
message' function might look something like:

   function getRandMsg(msgArray){
     var rn = Math.random()*msgArray.length | 0;
     return msgArray[rn];
   }

[...]

>     document.write(ideas[rand(ideas.length)])   

Calling document.write after the page is loaded will clear the entire
page before writing new content.  Use DOM or innerHTML to write new
content for the element.

Search the archives for scrolling banners that don't use a marquee
element.  I find them very annoying, they are little used - I suspect
many others find them annoying too.

Signature

Rob

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.