Jump to content

cursor to the end of a string


freelance84

Recommended Posts

The following code in the body tag  easily gets a cursor blinking in the desired form box when the page loads:

onload="document.form_1.t_description_entry.focus()

 

 

However, is it possible to get the cursor to jump the end of the text string in the said form box?

 

(my knowledge on js is very basic at the moment, so apologies if this is an ultra basic question)

Link to comment
https://forums.phpfreaks.com/topic/208994-cursor-to-the-end-of-a-string/
Share on other sites

Here is a bit of a hack, but it works in both IE and FF, did not try in other browsers:

 

function setFocusToEnd(fieldID)
{
    var inputObj = document.getElementById(fieldID);
    inputObj.focus();
    inputObj.value = inputObj.value;
}

 

Then just call the onload event using

onload="setFocusToEnd('t_description')

Assuming you gave the field an ID and not just a name.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.