Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    Php function called in javascript?


    This is probably a daft question but I'm new to javascript and really struggling!

    How can I call a php function from javascript?

    I've written a piece of javascript code so that a form pops up and a user fills in lots of inputs, which is passed to javascript to check.

    But, the function to pass all the input variables is written in php - how can I do this?

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Wheeling, IL
    Thanked 62 Times in 60 Posts
    JavaScript is purely a client-side language. As such, it is executed after server-side (PHP) execution. The only way you can call a php function from JavaScript is through an AJAX request. Though to do an AJAX request that would send the form's contents from JavaScript to PHP and then have them returned to JavaScript in the same format is rather pointless. Just collect the information in JS instead.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


    Posting Permissions

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