Why the JavaScript code is ignored from wp editor?

onclick is not i the list of allowed attributes. It will be removed by kses. You can filter the list, use Extend KSES for example.