Refactor service submission javascript