OK, I'm doing some basic validation inside of an ajax form callback. I'd like to use the result to execute some javascript. What I've tried looks something like this:
inside my form alter:
if (isset($form_state['values']['field_temp_age'])) {
if (validate())
{
//...return product information
} else {
drupal_add_js('alert("Validation fails!");', 'inline');
}
}
This doesn't work. In this case, nothing is returned.
Also, tried this from inside the ajax callback:
function my_ajax_callback(&$form, &$form_state) {
if (!validate()) drupal_add_js('alert("Foo!");', 'inline');
}
Not sure what's the approach here. How can I execute arbitrary javascript based on information returned from an ajax request?
Thanks.