How to add business logic with JavaScript