Page 1 of 1
Can you call a java fucntion from within php codes and V.V ?
Posted: Tue Nov 26, 2002 4:05 pm
by HappyTomato
somebody PLEASE answer this question if you know!!
Is it possible to call a java function from within php codes?? (ie within the <?php ?> tags.... if so, how??
Or, can you do this the other way round?? and if so... how...
Any help will be appreciated!!
Thank you in advance
Bo&Vic
Posted: Tue Nov 26, 2002 4:24 pm
by BigE
JavaScript is client-side, PHP is server-side, therfore the two cannot interact together. However, if you want JavaScript inside your PHP just do
Code: Select all
<?php
echo '<script type="JavaScript"> function jsfunction() { do JavaScript here; } </script>';
?>
Again, remember, the two cannot interact due to PHP being server-side and JavaScript being client-side. Hope that helps.
Posted: Tue Nov 26, 2002 4:32 pm
by hedge
I have never tried it but the manually implies that you could by using the java extension
http://www.php.net/manual/en/ref.java.php
Re: BigE
Posted: Tue Nov 26, 2002 5:05 pm
by HappyTomato
Re: BigE
Thanks for your suggestion, however does that mean we can still call a javascript function that's inside the php codes? For example, I have a parent window and a pop up window, when a button in the pop up window is clicked, it'll link back to a javascript function in the parent window (within the javascript language tags in <head> tags), but now if i move those functions into the php codes, can i still call them like i call normal javascript functions?

I know it may sound confusing but...... that's my best attempt in describing it....
Bo

Posted: Tue Nov 26, 2002 5:29 pm
by BigE
JavaScript is just like HTML, you call a JavaScript function through HTML code, therefore to call the function through PHP you would use something like this
Code: Select all
<?php
echo "<a href="blah.php" onclick="jsfunction()">Link</a>";
?>
Hope that helps.
Posted: Tue Nov 26, 2002 5:39 pm
by HappyTomato
sorry if the way i explained it was a bit confusing earlier... but what i meant was if i can call a javascript function located inside php tags from OUTSIDE the php tags.... like i said in the example above, from the pop-up window, i want to call the javascript function that's inside the php tag (the pop up window is not the same window as where the php tags are located).... hm.. is it a little bit clearer??
But anyway thanks for yout help in the last post, that information was valuable to me as well as i didn't know how to do that either...

.. (guess i'm really too much of a newbie... )
Bo

Posted: Tue Nov 26, 2002 5:50 pm
by volka
as already BigE mentioned php is server-side and javascript clientside.
although this is not completely correct you can assume that when the client processes the document stream generated by php your server-side php-script already ended.
All php does is to create a datastream that is interpreted as html and/or javascript by the client. But php doesn't care about that. It simply outputs character after character whatever it is, a html-document, an image, an archive, .... doesn't matter at all (almost

)
No interaction between php and the browser will take place until the next request. So there are only marginal differences between calling a script like
Code: Select all
<?php echo '<html><body>some text</body></html>'; ?>
and opening a plain file that contains
Code: Select all
<html><body>some text</body></html>
same with javascript