My js embedded form is not working properly each time