How to tell if a function is being called by javascript? I have a validation function that is being called either from another php function or a JavaScript call. I was wondering if there is a way to determine if the function is being called by JavaScript so that I can implement different functionality. I am using Drupal 7 for this but if you could post an answer for Drupal 6 too, I am sure that would help out other people as well.
JavaScript cannot directly call a PHP function. If you think that JS may be 'triggering' the call of that validation handler, then there must be an AJAX event going out to the backend, which then calls the validation handler. If that is the case, the request will go out to the system/ajax URI on your site (unless it has been intentionally changed to a different URI - you can double check this by viewing the 'Network' tab in Google Chrome's developer tools), which will then handle the request and dispatch it to the validation handler. 

So...

You can check the $_GET['q'] value in your validation handler:

if ($_GET['q'] == 'system/ajax') {
    // AJAX request
}
else {
    // other request
}