Passing variables to Javascript
Posted: Wed Nov 13, 2002 7:18 am
Sorry to be a pain (again!) but I've read the sticky on passing variables to JavaScript but still can't get it to work.
The code I'm using is as follows. The variable I want to pass to JavaScript is pulled from an external file using "include 'xxx'"
When I open the page, search for something then click to start the file playing, JavaScript tells me that sPath is undefined. I've tried a couple of variations on that, as shown in the example including using:
Sorry for being a pain
but does anyone have any idea why this couldn't be working. Just a point, the WindowsMediaPlayer control that the script is referencing to is outside the ?> of PHP.
jonat8
The code I'm using is as follows. The variable I want to pass to JavaScript is pulled from an external file using "include 'xxx'"
Code: Select all
<?php
include "config.inc.php";
echo("<b>Search Results: Click on the file's title to start the player.</b><br><br>");
$dbconn = mysql_connect($sServer, "$sUser", "$sPassword");
$result = mysql_select_db($sDB, $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
$sql = "SELECT * from dalmedia WHERE ".$D1." = '".$searchcriteria."'";
$result = mysql_query( $sql );
if ( $result != false )
{
while ( $data = mysql_fetch_assoc( $result ) )
{
echo 'Track Details: '.
$dataї'artist'].' (<a href="javascript:playMedia('.
$dataї'filename'].')"><b>'.
$dataї'trackname'].'</a></b>)';
}
} else {
echo ("Welcome, please enter your search criteria below.");
}
}
echo '<script language="JavaScript">
<!--
function playMedia(filename) {
WindowsMediaPlayer.FileName = $sPath + filename
}
//-->
</script>';
?>but that doesn't work either, when I load the page it tells me I have a syntax error.WindowsMediaPlayer.FileName = .$sPath. + filename
Sorry for being a pain
jonat8