When using drupal_add_js with the 'setting' option, do the set variables apply for all users?
Assuming that custom_get_username_function() returns a different username for each of the logged-in users, then that code will pass to JavaScript a different and a single username for each user. There could be 4 different logged-in user, but each user gets one username, assuming custom_get_username_function() is using the currently logged-in user ID to retrieve the username.

I would rather not add JavaScript code from a form submission handler; if I need to add it, I would add it to the form, or to the page where the users are redirected after they submit the form.