added the java script and refined the code so that it would work properly, need to include sucess and failure methods