Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2005
    Location
    San Diego, CA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling a Javascript function in PHP

    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?

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Jun 2005
    Location
    San Diego, CA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, I think I understand now. I found this article very useful when I wanted to do something similar, hopefully it'll give you some pointers.

  • #5
    New Coder
    Join Date
    Jun 2005
    Location
    San Diego, CA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder
    Join Date
    Nov 2004
    Location
    The Netherlands
    Posts
    551
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/...and_Templates/
    Last edited by mrruben5; 06-09-2005 at 10:16 AM.
    CATdude about IE6: "All your box-model are belong to us"

  • #7
    New Coder
    Join Date
    Jun 2005
    Location
    San Diego, CA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry didn't update this, I got everything sorted out...this is no longer an issue, thanks though


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •