...

View Full Version : Calling a Javascript function in PHP



entint
06-08-2005, 02:48 PM
Hello there, I was curious as to what the right way to call a javascript function in php is. I don't know too much about php, but if this is possible, it would be a huge help to me. Second thing I don't know is how to include the javascript code in php...can someone help me? :confused:

delinear
06-08-2005, 02:52 PM
What do you mean by calling a javascript function? Did you just want to output a javascript function using PHP or did you want to pass information from javascript to PHP (or vice versa)?

Essentially javascript is written exactly like HTML so if all you want to do is include some javascript in your page you can do so exactly as you would include HTML.

entint
06-08-2005, 02:56 PM
no no... okay here's the deal... I have an html form whose action posts to my php document. I was curious if the php document could call a javascript function I've written to return information to the html page, and if so, how?

P.S. This is semi-Ajax but it's very basic. I want to run an xmlhttprequest function in javascript from the php document....

delinear
06-08-2005, 03:09 PM
Oh, I think I understand now. I found this article (http://www.webpasties.com/xmlHttpRequest/) very useful when I wanted to do something similar, hopefully it'll give you some pointers.

entint
06-08-2005, 03:21 PM
actually I've read that article inside and out, and it did give me some great pointers, but I keep getting lost around the mySQL database and PHP stuff. I think most of the reason why is because I don't need a mySQL database for this to work, and also the PHP he uses is much more complex than the php I'm using.

Let me sum up my project in more detail for you and see if that helps...

I have an email form on my page which is contained within a div. On other pages, using solely javascript and links the inner html of that div is replaced by html from another file (this significantly cuts my bandwidth and file sizes). What I want to do is: Once the submit button has been pressed, go to the php document to find out which html document needs to be passed back to the client (currently using the readfile function). But instead of using the readfile function I want to use the javascript function I have written that replaces the inner html of the div....does that make more sense? Is this possible for me to do?

mrruben5
06-09-2005, 09:14 AM
Let me explain: Javascript is a client side scripting language, while php is server side.

Why don't you just use the index.php?page=news way? That's the most easy and it doesn't require javascript.

There's plenty of tutorials to help you.
http://www.pixel2life.com/tutorials/PHP_Coding/Navigation_and_Templates/

entint
06-09-2005, 10:29 AM
sorry didn't update this, I got everything sorted out...this is no longer an issue, thanks though :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum