By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,024 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,024 IT Pros & Developers. It's quick & easy.

passing parameter problems

P: n/a
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 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Isn't switch a reserved word in JS!?!

<al*********@gmail.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
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 '06 #2

P: n/a
Thanks Adrian,

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

Allan

Mar 1 '06 #3

P: n/a
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>

<al*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Thanks Adrian,

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

Allan

Mar 1 '06 #4

P: n/a
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 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.