SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member stuntace's Avatar
    Join Date
    Nov 2004
    Location
    Vancouver B.C Canada
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function run behavior

    I have a function parked in the head of an html page that seems to run on page load . I would rather call it where needed. Any ideas why it just runs on page open?. Maybe I'm just missing it... maybe a bit to here.
    Ty stuntace




    <SCRIPT LANGUAGE="JavaScript1.2">
    <!--

    function initArray() {
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++) {
    this[i] = initArray.arguments[i];
    }
    }

    var ctext = "Set: &nbsp -Initialize and script ActiveX controls not maked as safe- &nbsp to [Prompt] in Local intranet security.<br>";
    var speed = 1000;
    var x = 0;
    var color = new initArray("red","black");

    {
    document.write('<div id="c"><font face="Microsoft Sans Serif" size="2"><B><center>'+ctext+'</center></B></font></div>');
    }

    function chcolor() {
    {
    document.all.c.style.color = color[x];
    }
    (x < color.length-1) ? x++ : x = 0;
    }

    setInterval("chcolor()",2000);

    //-->
    </script>

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line:setInterval("chcolor()",2000); will perform the function chcolor() every 2000 millisconds starting when the page loads. The function chcolor() is not set up correctly. It looks like you have your brackets out of place or you have left out some code.

  3. #3
    SitePoint Member stuntace's Avatar
    Join Date
    Nov 2004
    Location
    Vancouver B.C Canada
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for pointing that out .

    function chcolor() {
    document.all.c.style.color = color[x];
    (x < color.length-1) ? x++ : x = 0;
    }

    That's better.

    So any idea what I'm not seeing here in the code that makes it load on page open?. I'm not calling this function from anywhere, such as "<body onload=function">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •