?
Solved

call php function in javascript

Posted on 2003-02-23
21
Medium Priority
?
544 Views
Last Modified: 2011-12-08
Hi,
can some one tell me how do i call a php function in a javascript code.
i need thisn very badly
thanks
bobbie
0
Comment
Question by:tn_bobbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +3
21 Comments
 

Author Comment

by:tn_bobbie
ID: 8006970
plz help me
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8007008
php is server side and javascript is client side.
They can only talk to each other by passing text to other side, but never invoke anything from opposite side directly.

Sorry.

0
 

Author Comment

by:tn_bobbie
ID: 8007029
But there must be a round about way atleast.
plz d help me
tx
bobbie
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:third
ID: 8007129
tn_bobbie,

  Zvonko is right. but if you can tell us what do you want to achieve then probably we can formulate another way than what you think.


regards,

third ;-)
0
 

Author Comment

by:tn_bobbie
ID: 8007225
hi ,
thanks for the response.
i'm actually rying to get the meta tags & description from a site whose url is mentioned by a user.
Presently i have a submit button which goes to next php page ,gets  the details & the populate the text areas with the details &the submoit the page to put details in the DB.
I now have 2 navigations(one to get the meta details & one to put in the DB).
But i want to restirct this  to only one.
so i have to actually call that php function in "on change" event of the corresponding text box(where the url is entered).
this is my goal.
so i wanted to call the php function in the javascript.
plz help me.
or can i get the meta details using the javascript?
thanks
bobbie
0
 
LVL 2

Expert Comment

by:neongrau
ID: 8008093
hi!

heres a basic strategy:

i recommend using a hidden iframe.

put a "get meta" button to your form. when pushing that button change the formaction's to your php-page that processes your needed meta information and the target to that hidden iframe.

there you can use all php functionality you'll need. at your php-pages end, create a javascript that fills that iframes parent.form with all collected information.

that should work (i've done almost the same using active server pages)

~neongrau
0
 

Author Comment

by:tn_bobbie
ID: 8008539
is there any possibility of getting these meta info using javascript
0
 
LVL 2

Expert Comment

by:neongrau
ID: 8008701
no, not javascript alone.

and thats because of security reasons.
the meta informations you want to access aren't from the same server your javascript resides.

parsing those would be easily possible but you need to read that pages source code. and that is something a browsers won't and shouldn't let you do.

(you wouldn't be amused if microsoft.com would read the other pages you're surfing on while running e.g. windowsupdate.com ;-))

so you need to load that pages source using a server-side side script (normally reading the first 20 lines should be enough to save bandwidth and time).
0
 
LVL 2

Expert Comment

by:neongrau
ID: 8008719
no, not javascript alone.

and thats because of security reasons.
the meta informations you want to access aren't from the same server your javascript resides.

parsing those would be easily possible but you need to read that pages source code. and that is something a browsers won't and shouldn't let you do.

(you wouldn't be amused if microsoft.com would read the other pages you're surfing on while running e.g. windowsupdate.com ;-))

so you need to load that pages source using a server-side side script (normally reading the first 20 lines should be enough to save bandwidth and time).
0
 

Author Comment

by:tn_bobbie
ID: 8008730
is there any possibility of getting these meta info using javascript
0
 
LVL 2

Expert Comment

by:neongrau
ID: 8008779
hehe, seems we both reloaded the page  *g*
0
 
LVL 1

Expert Comment

by:Gumbo
ID: 8008868
Try something like this:

<script type="text/javascript">
  document.write('<script type="text/php" scr="my.php">myphpFunction();</script>');
  document.write('<script language="php" scr="my.php">myphpFunction();</script>');
</script>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 8009083
Gumbo: huh???
0
 
LVL 1

Accepted Solution

by:
Gumbo earned 600 total points
ID: 8012472
You cannot call it directly from a javascript-script code, but you can call it in the HTML code with:

        <script type="text/php" scr="my.php">myphpFunction();</script>
or
        <script language="php" scr="my.php">myphpFunction();</script>
0
 
LVL 1

Expert Comment

by:Gumbo
ID: 8012501
Oh, typing error. It has to be 'src' not 'scr'.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 8014472
What browsers support php as scripting language?
0
 
LVL 1

Expert Comment

by:Gumbo
ID: 8025533
I think nearly all, just try it out.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 8025691
??? What do you mean - I know of no browser that supports client side php as scripting language
0
 

Author Comment

by:tn_bobbie
ID: 8025960
thanks a lot gumbo
0
 
LVL 2

Expert Comment

by:neongrau
ID: 8026165
this is no client side scripting but server side.
it's looking somehow confusing but its nothing more than a .shtml page with an alternate (not recommendable) writing of:

<?
require("myphp.php");
myphpFunction();
?>

if gumbos answer is correct than i think we totally misunderstood the whole question. ;-)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 8026367
I do believe we did...
The page that hits the browser no longer has any php in it and the script tags are gone too
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question