473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Junciton in PHP

How To Call Function within PHP code that is Defined in JavaScript in the
head section.
Apr 18 '07 #1
8 1464
devsusen
136 100+
please provide example or explain it in more details.
Apr 18 '07 #2
Atli
5,058 Expert 4TB
Hi.

I dont really understand your question.
It does however sound like your are trying to call a PHP function from JavaScript. If that is the case you should know that PHP is executed server side and JavaScript on the client so there is no way for JavaScript to call any PHP functions by any conventional means.
Apr 18 '07 #3
please provide example or explain it in more details.
Hi devsusen,
This is the example which is show below. Here The function inform()
is written in the Javascript in the head section.
How to call this function inform() within the PHP tag.

<HTML>
<HEAD>
<script language="javascript">
function inform()
{
.......code.
}
</script>
</HEAD>
<BODY>
<?php

//..............How to call funtion inform()

?>

I just want to asked that is it possible to call Javascript funtions with in the PHP tag that is with in <?PHP ....... ?>
Apr 19 '07 #4
Hi.

I dont really understand your question.
It does however sound like your are trying to call a PHP function from JavaScript. If that is the case you should know that PHP is executed server side and JavaScript on the client so there is no way for JavaScript to call any PHP functions by any conventional means.
Hi Atli,
This is the example which is show below. Here The function inform()
is written in the Javascript in the head section.
How to call this function inform() within the PHP tag.

<HTML>
<HEAD>
<script language="javascript">
function inform()
{
.......code.
}
</script>
</HEAD>
<BODY>
<?php

//..............How to call funtion inform()

?>

I just want to asked that is it possible to call Javascript funtions with in the PHP tag that is with in <?PHP ....... ?>
Apr 19 '07 #5
code green
1,726 Expert 1GB
You can't call the function inform() from PHP. But what you can do is call the function within HTML when the script is client side, and then pass values from the function via HTML variables to PHP server side when the user submits the page. We need a better explanation of what you are trying to achieve.
Apr 19 '07 #6
devsusen
136 100+
Hi Nilesh,

I am sorry to say there is no way to call the function inform(), written in Javascript within php code.

php scripts runs at server first, then the Javascript at client level. So in the php code section u can't call or execute a Javascript code or function. To get the same functionality of javascript u need write the code in php itself.

susen
Apr 20 '07 #7
Atli
5,058 Expert 4TB
I am sorry to say there is no way to call the function inform(), written in Javascript within php code.
This is not entirly true, tho PHP does not technically allow you to call client side scripts, you can have php print html code that does. So I would say PHP is capible of running JavaScript through the use of HTML.
Getting a value from the JavaScript method would be impossible tho without some trickery.

For example:
[HTML]
<script language="javascript">
function MessageBox(message) {
alert(message);
}
</script>

<?php
echo "<script language='javascript'> MessageBox('Hello'); </script>";
?>
[/HTML]

If you needed the JavaScrip method to return a value you could, for example, have JavaScript refresh the page and pass the value throught the HTTP GET protocol.
Apr 21 '07 #8
devsusen
136 100+
Hi,

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function MessageBox(message) {
  3.   alert(message);
  4. }
  5. </script>
  6.  
  7. <?php
  8.   echo "<script language='javascript'> MessageBox('Hello'); </script>";
  9. ?>
If I run this example the alert message will appear when the page is loaded in the browser. This means the javascript will be executed in the client level. But the result or the output of the function u can't get in the server level. in the php code u r basically printing the tag from where the function is called. I got ur point Atil.

I have used PHP coding to generate javascript code on fly.

susen
Apr 23 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Steve Jorgensen | last post by:
I've run across this issue several times of late, and I've never come up with a satisfactory answer to the best way to handle this schema issue. You have a large section of schema in which a...
1
by: Brian Henry | last post by:
I have a strange problem... I have a junction table that i need to filter based on a id, then take the filtered data and join it to a description table then show the data that was filtered in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.