Jump to content

[SOLVED] PHP & Java


mwkemo

Recommended Posts

Hello,

 

can PHP code be used inside java code?

 

<SCRIPT LANGUAGE="JavaScript">
OpenWindow.document.write("<?php echo NotWorking; ?>")
</SCRIPT>

 

Something like that? That's index.php file.This is not working for me, if I replace php code with html code then it's working. I need php inside java not html:-).

 

Any way to do that? Thanks

Link to comment
https://forums.phpfreaks.com/topic/178290-solved-php-java/
Share on other sites

first of all, java != javascript. second of all, you have to realize that javascript is client side, while PHP is server side. this means that javascript is executed by your browser, while PHP is executed by the web server.

 

as such, it is easy to write javascript with PHP, you just have to do something like

 

echo "<script type='text/javascript'> OpenWindow.document.write(\"".$NotWorking."\") </script>";

 

however, it is harder to get PHP values with javascript. you can make a hidden field with a PHP value, and access it via the HTML DOM that javascript has, for example

<input type="hidden" id="phpVal" value="<?php echo $someValue; ?>" />

<script type="text/javascript" >
phpval = document.getElementById('phpVal').value;
</script>

 

there are a couple of other ways, like with cookies.

 

what exactly are you trying to do? perhaps there is an easier way

Link to comment
https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940105
Share on other sites

Thanks for replays.

 

I'm trying to open new "window/small popup" when someone clicks on link. That is done with javascript. In this new window there must be php code. Here is the example:

 

<SCRIPT LANGUAGE="JavaScript">
function openindex()
      { 
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
OpenWindow.document.write("<?php function(); ?>")
OpenWindow.document.close()
self.name="main"
     }
</SCRIPT>

 

And this javascript is trigered with <a href="javascript:openindex()">LINK</a>

Link to comment
https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940111
Share on other sites

It's working:-). Did not need to put php inside javascript, I only needed to use javascript function to open new window. If I use javascript inside "<a href=" then firefox and IE open two window popups. But if I use javascript function and call that function from "<a href=" everything seems to be OK.

 

This is working code:

<script language="JavaScript">
function openKlubovi()
      {
window.open("index.php?klubovi", "klubovi", "height=300, width=400");
     }
</script>

 

and link:

<a href="javascript:onLoad=openKlubovi()">Klubovi</a>

 

Thanks for all the Help

Link to comment
https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940121
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.