• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

How do I pass php GET parameters through to a JavaScript routine?

I am using PHP, MySQL, JavaScript, XML/SWF Charts (which is great) but it has a line...

'FlashVars', 'library_path=charts_library&xml_source=my_chart_xml.php',  in a call to the main JavaScript interface .... I want to call the my_chart_xml.php with a variable parameter, e.g....

'FlashVars', 'library_path=charts_library&xml_source=my_chart_xml.php?myparam=$value',

how do I do that?
0
me_patrick
Asked:
me_patrick
  • 3
  • 3
1 Solution
 
hieloCommented:
somewhere you probably have:
echo "...'FlashVars', 'library_path=charts_library&xml_source=my_chart_xml.php?myparam=$value', ...";

try:
echo "...'FlashVars', 'library_path=charts_library&xml_source=my_chart_xml.php?myparam=" . encodeurl($value) . "', ...";
0
 
me_patrickAuthor Commented:
No, it's a parameter to a call to javascript - it's all within a
<script language="JavaScript" type="text/javascript"> tag.

0
 
hieloCommented:
post what you have
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
p_nutsCommented:
post a sample for us pls

 but I think howling is right. just add it to the file name.
0
 
me_patrickAuthor Commented:
This is the product I am using (which is very good) .... http://www.maani.us/xml_charts/index.php ... everything about how this works and can be used is there.

This is my actual call (through the JavaScript interface)   ....

        <script language="JavaScript" type="text/javascript">
        <!--
        if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
            alert("This page requires AC_RunActiveContent.js.");
        } else {
            var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
            if(hasRightVersion) {
                AC_FL_RunContent(
                    'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',
                    'width', '600',
                    'height', '400',
                    'scale', 'noscale',
                    'salign', 'TL',
                    'bgcolor', '#777788',
                    'wmode', 'opaque',
                    'movie', 'charts',
                    'src', 'charts',
                    'FlashVars', 'library_path=charts_library&xml_source=entries_chart_xml.php',
                    'id', 'my_chart',
                    'name', 'my_chart',
                    'menu', 'true',
                    'allowFullScreen', 'false',
                    'allowScriptAccess','sameDomain',
                    'quality', 'high',
                    'align', 'middle',
                    'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                    'play', 'true',
                    'devicefont', 'false'
                    );
            } else {
                var alternateContent = 'This content requires the Adobe Flash Player. '
                + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
                document.write(alternateContent);
            }
        }
        // -->
        </script>

Basically I just want to pass parameters through this interface between the calling php code (which is the wrapper for the interface), and the subordinate php routine that actually does the work (see the FlashVars line above).

I'm getting around this at the moment by creating a session variable and then picking it up but I just imagined there would be a more direct way of doing it - no?



0
 
hieloCommented:
try:
<?php
//these are the parameters you want to send
$paramsForXML=array(	"username"=>"johnny"
					,"password"=>"XXX"
					,"name"=>"john smith"
					,"status"=>"suspended"
				);
//this is the url where you want to send the request to
$url='entries_chart_xml.php?';
foreach($paramsForXML as $k=>$v)
{
	$url.= urlencode($k)"=".urlencode($v)."&";
}
$url=urlencode(substr($url,0,-1));

?>
 <script language="JavaScript" type="text/javascript">
       <!--
       if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
           alert("This page requires AC_RunActiveContent.js.");
       } else {
           var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
           if(hasRightVersion) {
                AC_FL_RunContent(
                   'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',
                   'width', '600',
                   'height', '400',
                   'scale', 'noscale',
                   'salign', 'TL',
                   'bgcolor', '#777788',
                   'wmode', 'opaque',
                   'movie', 'charts',
                   'src', 'charts',
                   'FlashVars', 'library_path=charts_library&xml_source=<?php echo $url; ?>',
                    'id', 'my_chart',
                   'name', 'my_chart',
                   'menu', 'true',
                   'allowFullScreen', 'false',
                   'allowScriptAccess','sameDomain',
                   'quality', 'high',
                   'align', 'middle',
                   'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                   'play', 'true',
                   'devicefont', 'false'
                   );
            } else {
                var alternateContent = 'This content requires the Adobe Flash Player. '
               + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
               document.write(alternateContent);
            }
       }
       // -->
       </script>

Open in new window

0
 
me_patrickAuthor Commented:
Thanks Hielo - that was the answer to that. Now (only sometimes) for some reason the chart is not responding to changes in the underlying charting data .... very puzzling but a different question alltogether.
You've been a great help.
Patrick.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now