I believe the reason why the onclick function was removed after you saved and re-entered the source code is because the source only support html and css. However, the onclick function is a javascript code as such it's not supported.
To add javascript on your pages, these are some of the options: