Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Not working Javascript

See following code. Little bit of php, some Javascript & HTML.

$fname= "testersrpt/test" . date('Y-m-d') . ".pdf";
$pdf->Output($fname, "F");			
?>
<!DOCTYPE html>

<html>
<head>
<title>Untitled</title>
<script>
str = "<? print $fname; ?>";
	function on_load() {
		window.open(str);
		window.location = "gen_testers_by_city.php";
	}	
</head>
<body onload="on_load();">



</body>
</html>	

Open in new window


My intent is for the browser to open (in a separate window) the file called str (which is IN that folder) and to redirect to gen_testers_rpt.php (in the same forder we are presently in).

It does neither.

It shows several echos I have inserted for debug purposes & the rest a blank scree.

Why?

Why
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

You need the php tag for the output to work:

str = "<?php print $fname; ?>";

Open in new window

When debugging, it really helps to turn on error_reporting, keep an eye on the console, and do a View Source. These will all help you to identify problems in your code.

FYI - The window.open() may be blocked by your browser - xxx prevented a pop-up from opening
Avatar of Richard Korts

ASKER

I don't think the missing php matters. I have thousands of code lines that start <? and all work fine. But I did it your way, here is view source.

I put in error_reporting(E_ALL); at the top.

<br />
<b>Notice</b>:  Undefined index: trptall in <b>/home/backflow/public_html/testers_by_city.php</b> on line <b>22</b><br />
<br />
<b>Warning</b>:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in <b>/home/backflow/public_html/testers_by_city.php</b> on line <b>154</b><br />
<!DOCTYPE html>

<html>
<head>
<title>Untitled</title>
<script>
str = "testersrpt/test2018-06-22.pdf";
	function on_load() {
		window.open(str);
		window.location = "gen_testers_by_city.php";
	}	
</head>
<body onload="on_load();">



</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As usual, something obvious that I missed.

Works perfect now.

Thanks for catching it.

Richard