Adding inline JavaScript encoding issue

1) For escaping content of textarea you should use esc_textarea and not esc_attr.

2) You should not escape things when storing them in the DB, escaping should be done only at output time. (I assume that you can find an edge case in which it might be needed, but as a general rule, just don’t do it).

3) Asking users to insert JS code is very user hostile. In addition to the obvious security problem that might arise a general type of breakage is almost un avoidable… think someone doing $ = 'dollar';. It doesn’t help that if you go that way you have no way to sanitize anything and have to serve it raw.