Handle events and manipulate strings using JavaScript?