ellandrd
asked on
pass value to external javascript file
i place all my javascripts in an external file. it is possible to pass values to functions?
i set some variables using PHP that i want to pass to my external javascript file.
i have tried this but didnt work:
<?php
$navigationHeight = 360;
?>
<script type="text/javascript" src="/scripts/global.js?na vigationHe ight=<?php echo $navigationHeight; ?>"></script>
in my global.js file i done this:
resizeDivHeight.custom(0,l ocation.se arch);
please advise
i set some variables using PHP that i want to pass to my external javascript file.
i have tried this but didnt work:
<?php
$navigationHeight = 360;
?>
<script type="text/javascript" src="/scripts/global.js?na
in my global.js file i done this:
resizeDivHeight.custom(0,l
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
your idea works perfect. why didnt i think of that... it was sitting looking at me but i had "passing the URL values" to the JS file in my head since earlier in work and when i came home, my mind was messed up...
thanks for the knock in the head and making me see sense.
ellandrd
thanks for the knock in the head and making me see sense.
ellandrd
glad you got it working :)
>>it was sitting looking at me but i had "passing the URL values" to the JS file...
This often comes with too much PHP scripting....
This often comes with too much PHP scripting....
ASKER
solution
// i set some values in my PHP page - the 360 is just an example that is fit for purpose...
<?php $navigationHeight = 360; ?>
// this is how i pass the PHP values into my Javascript function
<div id="banner"><a href="javascript:void(0);" id="toggle" onclick="javascript:toggleNavigationBar(<?php echo $navigationHeight; ?>);return false;" title="Click here to toggle my navigation bar">Click Here</a></div>
// my src to my external JS file at the bottom of my page
<script type="text/javascript" src="/scripts/global.js"></script>
// function inside JS file
function toggleNavigationBar(height)
{
if(navigationOpened == false)
{
resizeDivHeight.custom(0,height);
navigationOpened = true;
}
else
{
resizeDivHeight.custom(height,0);
navigationOpened = false;
}
}
ASKER