JS: jQuery functions for handling cursor position in input fields