5 Replies - 1328 Views - Last Post: 15 October 2002 - 12:35 PM

#1 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Php In Javascript

Posted 26 September 2002 - 08:30 AM

is there a way to include php in a javascript function?

because this:

<script LANGUAGE="Javascript">
if (screen_size.width<=800||screen_size.height<=600) {
<?
	$show = 4;
?>
} else {
<?
  $show = 6;
?>
}
</SCRIPT>



doesn't seem to be working.... *sigh*
Is This A Good Question/Topic? 0
  • +

Replies To: Php In Javascript

#2 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Php In Javascript

Posted 26 September 2002 - 08:32 AM

i take it back, hehe, it does work :)
Was This Post Helpful? 0
  • +
  • -

#3 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Php In Javascript

Posted 26 September 2002 - 08:48 AM

i take it back, it doesn't work :( *sigh*
Was This Post Helpful? 0
  • +
  • -

#4 gneato  Icon User is offline

  • <title>Untitled Document</title>

Reputation: 0
  • View blog
  • Posts: 1,311
  • Joined: 03-September 01

Re: Php In Javascript

Posted 26 September 2002 - 09:19 AM

I got it straigtened out. Ended up using this code.

<HTML>
<head>
<? 
if (!$show) { 
?>
<script LANGUAGE="Javascript">
    if (screen.width <= 800 || screen.height <= 600) {
        document.location.href = "<? echo $PHP_SELF;?>?show=4";
    } else if (screen.width > 800 || screen.height > 600) {
        document.location.href = "<? echo $PHP_SELF;?>?show=6";
    }
</SCRIPT>
<?
} ?>
</head>

<body>
<? 
if ($show == 6) { 
echo "<h2>You have over 800x600 res!</h2>"; 
} else { 
echo "<h2>You have 800x600 or under</h2>"; 
}
?>

</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#5 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Php In Javascript

Posted 26 September 2002 - 09:26 AM

perfect perfect, thanks gneato :)
Was This Post Helpful? 0
  • +
  • -

#6 LuxFX  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 09-August 01

Re: Php In Javascript

Posted 15 October 2002 - 12:35 PM

here's a couple of quick tips based on gneato's answer:

<? echo $PHP_SELF; ?>

can be abbreviated as:

<?=$PHP_SELF?>

The '<?=' will print out a string or variable or whatever.

The other thing is that on recent installs of PHP, I think it's 4.2 or 4.0.2 or something, there is a safety mode enabled by default and $PHP_SELF is no longer accessible. Instead, use this:

<?=$_SERVER["PHP_SELF"]?>


cheers!
-LuxFX
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1