Drew
Drew

Reputation: 1261

Javascript not pulling php variables, page not loading php?

I have a site online to test and edit using "000webhost.com" which has php and mysql.

Either javascript is not pulling the PHP variables or the site is not loading php.

when I load the page I start up chrome code viewer to check the code live. when looking over the default.php (index page) it does not show my php variables.

Javascript

window.onload = function(){
var iso = "<?= $isop; ?>";
var meg = "<?= $megp; ?>";
var mex = "<?= $mexp; ?>";
var mor = "<?= $morp; ?>";
var noc = "<?= $nocp; ?>";
var pye = "<?= $pyep; ?>";
var tri = "<?= $trip; ?>";
var zyd = "<?= $zydp; ?>";
}

php page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Str8nge Brew Calculator</title>
</head>
<body>
<?php
$isop = "1";
$megp = "1";
$mexp = "1";
$morp = "1";
$nocp = "1";
$pyep = "1";
$trip = "1";
$zydp = "1";
?> 
<script type="text/javascript" src="calceve.js"></script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
....
</body>

Upvotes: 0

Views: 190

Answers (2)

Drew
Drew

Reputation: 1261

I fixed it by taking all the javascript code and moving it inside the tag on the php page. not sure why this fixes it exactly but it works. I did also move the window.onload so the var are first

Upvotes: 0

Robbert
Robbert

Reputation: 6592

If you want your calceve.js file to render the PHP contained within, you'll need to change the file extension to .php, src="calceve.php". Whenever I have a javascript file that contains PHP, I use something like myfile.js.php, just to keep it straight in my head what the file actually is.

Upvotes: 2

Related Questions