Is it possible to embedd php in javascript?

Javascript coding ..

Moderators: macek, egami, gesf

Mazerman
New php-forum User
New php-forum User
Posts: 12
Joined: Sun Jan 26, 2003 2:57 pm
Location: Sweden

Is it possible to embedd php in javascript?

Postby Mazerman » Thu Jul 03, 2003 12:47 pm

Hi!

I would like to know if it is possible in some way to embedd php in javascript. I tryed the code below but it didn't work. Would be thankful if someone knows if it's possible or if there is another way of doing it:

Code: Select all

<script language="JavaScript" type="text/JavaScript">
<!--
function testJava()
{ //v2.0
   <?php
      echo "hello";
   ?>
   return 0;
}
//-->
</script>

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Thu Jul 03, 2003 1:10 pm

PHP executes on the server only. To get the results you want you will have to output JavaScript code with php.

Here's the code that will make your test program work.

Code: Select all

<script language="JavaScript" type="text/JavaScript">
<!--
function testJava()
{ //v2.0
   document.write("<?php
      echo "hello";
   ?>");
   return 0;
}
//-->
</script>

Mazerman
New php-forum User
New php-forum User
Posts: 12
Joined: Sun Jan 26, 2003 2:57 pm
Location: Sweden

Postby Mazerman » Thu Jul 03, 2003 4:48 pm

thnx!!


Return to “JavaScript”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest