passing parameter problems

Discussion in 'Javascript' started by allanrodkin@gmail.com, Mar 1, 2006.

  1. Guest

    Hi, I'm designing a website in dreamweaver and I'm using JavaScript to
    slide text across the page. The text is contained in <div> tags. I
    have designed a function which can move two of the div tags across the
    screen. I use the timer to manage the movement of the text across the
    screen. I would like redesign that function so that it can move any
    amount of div blocks across the screen. To do this, I need to pass a
    parameter to the function moveParas()

    The following set up works fine, calling moveParas which moves two div
    code blocks across the screen:

    function window_onload()
    {
    window.setInterval("moveParas()",1);
    }

    <--moveParas() is located at the bottom of the screen-->
    ---------------------------------------------------------------------------------------------------------------------------
    I have tried to change moveParas() so that it can accept paramaters. I
    have tried to pass it variables and hardcoded coded value, but this is
    not working. I have of course altered the function itself to accept a
    parameter.

    function window_onload()
    {
    var dog = false;
    window.setInterval("moveParas(dog)",1);
    }

    I know the code is causing errors because because the the original div
    blocks, which should remain unaffected, stop sliding across the page

    Another thing is happening. Dreamweaver will not allow me to create
    new JavaScript variables. I know this because in the Firefox
    Javascript console, it gives me the error, "no formal definition" for
    any new variables I declare beyond those that are contained in the
    moveParas() function contained at the bottom of the page). does anyone
    have any idea why that is happening?

    I'd really appreicate if someone could help me solve this problem.
    forgive me if it is a simple Javascript problem because I am a
    Javascript amateur.

    <--here is moveParas() -->
    function moveParas(switch)
    {
    alert(switch);
    var paraTwo = document.getElementById("paraTwoID");
    var paraOne = document.getElementById("paraOneID");
    if (paraOneLeft >= 20)
    {
    paraOne.style.left = 20 + 'px';
    stop = true;
    }
    else
    {
    paraOneLeft++;
    paraOne.style.left = paraOneLeft + 'px';
    }


    if (stop==true){
    if (paraTwoLeft >=100)
    {
    paraTwo.style.left = 100 + 'px';
    }
    else
    {
    paraTwoLeft++;
    paraTwo.style.left = paraTwoLeft + 'px';
    }
    }
    }
    </SCRIPT>
     
    , Mar 1, 2006
    #1
    1. Advertising

  2. Adrian Guest

    Isn't switch a reserved word in JS!?!

    <> wrote in message
    news:...
    > Hi, I'm designing a website in dreamweaver and I'm using JavaScript to
    > slide text across the page. The text is contained in <div> tags. I
    > have designed a function which can move two of the div tags across the
    > screen. I use the timer to manage the movement of the text across the
    > screen. I would like redesign that function so that it can move any
    > amount of div blocks across the screen. To do this, I need to pass a
    > parameter to the function moveParas()
    >
    > The following set up works fine, calling moveParas which moves two div
    > code blocks across the screen:
    >
    > function window_onload()
    > {
    > window.setInterval("moveParas()",1);
    > }
    >
    > <--moveParas() is located at the bottom of the screen-->
    > ---------------------------------------------------------------------------------------------------------------------------
    > I have tried to change moveParas() so that it can accept paramaters. I
    > have tried to pass it variables and hardcoded coded value, but this is
    > not working. I have of course altered the function itself to accept a
    > parameter.
    >
    > function window_onload()
    > {
    > var dog = false;
    > window.setInterval("moveParas(dog)",1);
    > }
    >
    > I know the code is causing errors because because the the original div
    > blocks, which should remain unaffected, stop sliding across the page
    >
    > Another thing is happening. Dreamweaver will not allow me to create
    > new JavaScript variables. I know this because in the Firefox
    > Javascript console, it gives me the error, "no formal definition" for
    > any new variables I declare beyond those that are contained in the
    > moveParas() function contained at the bottom of the page). does anyone
    > have any idea why that is happening?
    >
    > I'd really appreicate if someone could help me solve this problem.
    > forgive me if it is a simple Javascript problem because I am a
    > Javascript amateur.
    >
    > <--here is moveParas() -->
    > function moveParas(switch)
    > {
    > alert(switch);
    > var paraTwo = document.getElementById("paraTwoID");
    > var paraOne = document.getElementById("paraOneID");
    > if (paraOneLeft >= 20)
    > {
    > paraOne.style.left = 20 + 'px';
    > stop = true;
    > }
    > else
    > {
    > paraOneLeft++;
    > paraOne.style.left = paraOneLeft + 'px';
    > }
    >
    >
    > if (stop==true){
    > if (paraTwoLeft >=100)
    > {
    > paraTwo.style.left = 100 + 'px';
    > }
    > else
    > {
    > paraTwoLeft++;
    > paraTwo.style.left = paraTwoLeft + 'px';
    > }
    > }
    > }
    > </SCRIPT>
    >
     
    Adrian, Mar 1, 2006
    #2
    1. Advertising

  3. Guest

    Thanks Adrian,

    switch is a reserved word but I changed switch to "blah" and I still
    got the same problems

    Allan
     
    , Mar 1, 2006
    #3
  4. Adrian Guest

    Hi
    below is a complete HTML page that passes text which is then displayed
    via your alert that is working...
    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head>

    <title>Untitled Page</title>

    <script type="text/javascript" language="javascript">


    function moveParas(testit)

    {

    alert(testit);

    var paraTwo = document.getElementById("paraTwoID");

    var paraOne = document.getElementById("paraOneID");

    if (paraOneLeft >= 20)

    {

    paraOne.style.left = 20 + 'px';

    stop = true;

    }

    else

    {

    paraOneLeft++;

    paraOne.style.left = paraOneLeft + 'px';

    }



    if (stop==true){

    if (paraTwoLeft >=100)

    {

    paraTwo.style.left = 100 + 'px';

    }

    else

    {

    paraTwoLeft++;

    paraTwo.style.left = paraTwoLeft + 'px';

    }

    }

    }

    </SCRIPT>

    </head>

    <body onload="moveParas('test');">

    </body>

    </html>



    <> wrote in message
    news:...
    > Thanks Adrian,
    >
    > switch is a reserved word but I changed switch to "blah" and I still
    > got the same problems
    >
    > Allan
    >
     
    Adrian, Mar 1, 2006
    #4
  5. Guest

    Hi Adrian,

    Thanks for the help. the only problem was that I was missing a
    semicolon after the second onload function call

    Thanks Again
     
    , Mar 2, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ranginald
    Replies:
    4
    Views:
    4,021
    Ranginald
    May 1, 2006
  2. Replies:
    4
    Views:
    532
    Matteo
    Mar 29, 2007
  3. Stuart Redmann
    Replies:
    5
    Views:
    494
    Stuart Redmann
    Dec 14, 2007
  4. Mister B
    Replies:
    8
    Views:
    568
    Nick Keighley
    Aug 26, 2010
  5. aidy
    Replies:
    2
    Views:
    89
    Kenosis
    Jun 20, 2006
Loading...

Share This Page