You need to add callback for the form submission. Something like this
function your_module_form_alter(&$form, &$form_state, $form_id) {
if ($form['#form_id'] == 'your_form_id') {
$form['#submit'][] = 'custom_callback';
}
}
function custom_callback() {
drupal_set_message('This is my custom message');
}
Now, after the form submission, the custom_callback
will also be executed.
If the code is Javascript and the form submission is via Ajax, you may have a look at the Ajax framework and Ajax framework commands topics in the API documentation. How to execute custom javascript code after an ajax succes (using the Drupal Ajax framework) ? is another useful page/