javascript function to simulate typing