Page 1 of 1

Another JavaScript problem

Posted: Mon Nov 18, 2002 9:59 am
by jonat8
Hi (again!)

I have the following code:

Code: Select all

<SCRIPT LANGUAGE=JavaScript>

	function playMedia &#123;
		/mediabase/" + <?php echo $searchcriteria?>;
	&#125;

</SCRIPT>
which I access through a link, i.e.

Code: Select all

<a href="javascript:playMedia()">
But whenever I click on the link I get the following error: "Object Expected" at Line 1, Char. 1. The second part of the filename is retrieved from a database, hence the need to echo $searchcriteria.

I tried changing the code inside the playMedia function to just an alert saying "hello" and I got the same error, so I assume the problem must be elsewhere. My code is:

Code: Select all

<? include "playheader.inc.php" ?>

<?php

include "config.inc.php";

$D1 = "filename";

$dbconn = mysql_connect($sServer, "$sUser", "$sPassword");
$result = mysql_select_db($sDB, $dbconn);
if ( $result == false )
&#123;
	echo mysql_error();
&#125; else &#123;
	$sql = "SELECT * from dalmedia WHERE ".$D1." = '".$searchcriteria."'";

	$result = mysql_query( $sql );
	if ( $result != false )
	&#123;
		while ( $data = mysql_fetch_assoc( $result ) )
		&#123;
			echo ("Record successfully retrieved");
		&#125;
	&#125; else &#123;
		echo ("No filename passed. Please go back and search for another file!");
	&#125;
&#125;



?>


<body background="exptextb.jpg">
<a href="javascript:playMedia()"> Play<a>

<center>
<img src="exphorsa.gif" width=300 height=10>
</center>
<SCRIPT LANGUAGE=JavaScript>

	function playMedia &#123;
		alert("hello")
	&#125;

</SCRIPT>
All the 2 includes contain is a)the title bar - in "playheader.inc.php" and b)the connection info to the database - in "config.inc.php"

Would appreciate any help! Thanks :)
jonat8[/quote]

Posted: Mon Nov 18, 2002 11:53 am
by volka
javascript is not visual basic ;)
always

Code: Select all

function nameOfFunction(parameter1, parameter2, ...) &#123;  &#125;
if there are no parameters

Code: Select all

function nameOfFunction() &#123;  &#125;
what is
/mediabase/" + <?php echo $searchcriteria?>;
supposed to do?