PDA

View Full Version : passing a variable through OnClick..


Reiss
02-08-2008, 08:10 AM
Hi guys
I really don't know javascript at all (php is my thing), have been relying on dreamweaver to insert the correct script for me.

Anyway, I have animated a div tag using DW timeline, and have moved my javascript functions to an external php file hoping I could do a $_get to extract variables
<?php include("include/javascript_functions.php");?>

I have the same piece of script that scrolls the div tag up, and then goes to a new url when finished. I want to be able to use the same script but change the url accordingly. here's my call -

<td><a href="#" onclick="MM_timelinePlay('Timeline2')">Link 1</a></td>

and heres the piece of script that does the url change -

document.MM_Time[1][1].value = "MM_goToURL('parent','index.php')";

what I want to do is have the url dynamic and pass it to the javascript function
eg.. $link = index.php

<td><a href="#" onclick="MM_timelinePlay('Timeline2', $link)">Link 1</a></td>

and the script -

document.MM_Time[1][1].value = "MM_goToURL('parent',$link)";

I could do this easily with php using a get or something, but with javascript im stumped.

cheers

Reiss
02-12-2008, 05:59 AM
FIXED

I wrote my first bit of javascript - basic, but does the job.

I wrote a function called 'dostuff' which accepted a variable, so my link would be -
onclick="dostuff('index.php')" or onclick="dostuff('contact.php')"

the function -
function dostuff(newpage1)
{
newpage = newpage1;
MM_timelinePlay('scrollup');
}

and the link bit

document.MM_Time[1][1].value = "MM_goToURL('parent',newpage)";

I know this is real basic stuff, but for someone who knows zero JS, I'm quite proud of myself!