views:

96

answers:

2

you can easily find focus() answers from the site or any site.. but what i want to know, how can i use focus after what i just inserted inside the input box.

$("input").val('@user').focus(); // this goes to start of the input box and foucs from start, but i want it to focus after the @user

$("input").val('@user today i did new things').focus(5); // i added 5 in focus method, obviously its not supported yet!, but the idea behind is, to focus it after @user from complete word.

EDITED:

i just saw that on firefox it works fine, but in chrome it starts the cursor from start. any solution?

A: 

Take a look at this question: http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area

Seb
A: 

You can focus an input area by triggering it on change event:

$("input").change(function(){
   $(this).focus();
});

and if you want to check how many characters typed you can make a control on its callback:

//will focus if typed text's length is greater than 5
$("input").change(function(){
   if($(this).val().length > 5){
     $(this).focus();
   }
});

hope it helps, Sinan.

Sinan Y.
it wont focus after the words.. it fouces before the word. i need it to focus after
Basit
i think you mean setting caret position here not focusing into an input element. Anyway the link in Seb's answer is a good resource to look at.
Sinan Y.