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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.