Set cursor position at the end of HTML field

kreddyT
Mega Contributor

Hello,

I am calling save function at a set interval. I am setting the focus to an HTML field on my form but the cursor stands at the beginning of the text in HTML field each time the form loads. How can I write a script that puts the cursor at the end of the text in that field?

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi,



Using g_form.getControl(fieldname), you may be able to use something like this:



Move Cursor to End of Input | CSS-Tricks



I haven't tried it, but once you have the element, you may be able to take advantage of other methods and properties.



GlideForm (g form) - ServiceNow Wiki  


Hello Chuck,



I used this code already but it didnt work. It works for the regular string fields but the HTML field on my form auto-saves every 5 mins. Whenever it is autosaved, the carat jumps to the previous line. Meaning, if a user is typing something in line 10, the cursor jumps to line 9 after autosave is called. I am trying to fix this by setting the cursor position to the end of the text after autosaving HTML field. Here is the screenshot of code I am using,



5-13-2016 8-59-30 AM.png


Here is the script include :


5-13-2016 9-07-51 AM.png


Hi Keerthana,



I have to defer to smarter client scripting minds than mine. Often things like this get down to browser compatibility which is why we always encourage people to use the ServiceNow API whenever possible. In this case, it doesn't appear that you can. Hopefully someone with better client side scripting skills than I can help (and provide a browser independent solution that limits upgrade issues.)


Hello Chuck,



Thank you so much for you reply.


I tried other pieces of code and ended up being unsuccessful. Now, I am trying to save the value of that particular field ("u_execution" in my case) to a file(be it a .txt or .doc) on desktop for every 5 mins. Would you please help me in guiding me how to get this done?




Any kind of help is highly appreciated.