passing parameter problems

A

allanrodkin

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>
 
A

allanrodkin

Thanks Adrian,

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

Allan
 
A

Adrian

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>
 
A

allanrodkin

Hi Adrian,

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

Thanks Again
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top