Thanks. That's the method I'm using.
For anyone else searching for this, here's a mini tutorial.
Variables in javascript work a little diferent from php. Here's some code to exemplify:
//PHP
$a=2;
function test (){
echo $a;
}
// this will throw back an error of undefined variable
$a=2;
function test (){
global $a;
echo $a;
}
// this will output: 2
So as you can see, in PHP, if you want to use an existing variable inside a function, you must first declare it global.
Now in javascript:
//JAVASCRIPT
var a=2;
function test(){
alert (a);
}
//this will popup an alert window with: 2
In javascript, once a variable is declared (outside a function) it exists in all space. In example 2, if you declare a variable inside a function:
function test(){
var a=2;
}
alert (a);
//this throws a variable undefined error.
In this scenario, all variables declared inside a function are only local. This applies both to javascript and PHP.
Now back to my original problem.
In XOOPS there are 2 smarty variables you will use a lot: $xoops_url and $xoops_rootpath, since we can't use smarty directly in javascript files, how do we pass these values?
Step 1:
in your XOOPS smarty template:
style>
<script language="javascript">
var xoopsRoot="<{$xoops_rootpath}>";
var xoopsUrl="<{$xoops_url}>";
script>
<link rel="stylesheet" href="<{$xoops_url}>/modules/greenlime/templates/js/newpost.css" type="text/css" media="all" />
<script type="text/javascript" src="<{$xoops_url}>/modules/greenlime/templates/js/jquery-1.3.2.min.js">script>
Now I can use the javascript variables "xoopsRoot" and "XoopsUrl" inside any javascript file that comes after.
You can do this for any other smarty variable (even your own)
..for a mini tutorial, not to shaby