finalised js form validation method