Fix some error in my JS function