mwkemo Posted October 19, 2009 Share Posted October 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/ Share on other sites More sharing options...
simshaun Posted October 19, 2009 Share Posted October 19, 2009 First, that is javascript, not java. Second, surround "NotWorking" with quotes. Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940102 Share on other sites More sharing options...
mikesta707 Posted October 19, 2009 Share Posted October 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940105 Share on other sites More sharing options...
mwkemo Posted October 19, 2009 Author Share Posted October 19, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940111 Share on other sites More sharing options...
Pawn Posted October 19, 2009 Share Posted October 19, 2009 I hope you have a really, really good reason to use popups. Many users/browsers will block them by default. Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940113 Share on other sites More sharing options...
mwkemo Posted October 19, 2009 Author Share Posted October 19, 2009 It's for my personal use. I am building php script for managing tournaments. This popup is used for filing form when I wont to add new tournament or player. Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940114 Share on other sites More sharing options...
mwkemo Posted October 20, 2009 Author Share Posted October 20, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178290-solved-php-java/#findComment-940121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.