View Full Version : Php function called in javascript?

06-01-2009, 11:55 AM

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?

06-01-2009, 03:12 PM
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.