added proper event listener for javascript functionality