set focus at end of text in inputbox after ajax refresh

set focus at end of text in inputbox after ajax refresh

  

Hi All,

whenever we do ajax refresh on the inputbox cursor moves to the beginning of the text. If i want to keep the position of it or move it to the last. Is there any inbult way to do it.

Regards,

Manish Jawla

Manish Jawla wrote:

Hi All,

whenever we do ajax refresh on the inputbox cursor moves to the beginning of the text. If i want to keep the position of it or move it to the last. Is there any inbult way to do it.

Regards,

Manish Jawla


Hi Manish

You can use this javascript associated with your input:

"$('" + YourInput.Id + "').focus(function(){
  var that = this;
  setTimeout(function(){ that.selectionStart = that.selectionEnd = 10000; }, 0);
});"

Hope this helps.
Cheers, 

Eduardo Jauch

hi Eduardo Jauch,

Thank you so much for the quick response but when i tried the above javascript code in my personal environment it works fine but when i applied the same in my company application its not working :(. May be some conflict issue but i have already applied the no.conflict(); also but still not working.

Regards,

manish jawla

Hello Manish,

When you try it with company's application, if you inspect the app in browser and look to the console messages, their is anything? Errors?

Can be a conflict with other JavaScript in the page.

Cheers

Eduardo Jauch

Hi Eduardo Jauch ,

XML5632: only one root element is allowed.

This error message is appering while inspect element but same error is also coming in my personal environment and its working fine. I am using internet explorer 11 for the info.

cheers

Regards,

manish jawla 

Hello Manish,

This error is related to edge and probably is the same thing with IE. See here. It has no impact in the application, it seems.

The reason to the JavaScript to work in your personal, but not in your other application, if you are using the same browser version and the server version is the same, is probably related to other script in the page. 

Do you have any mask or any other widget associated with the input?

Cheers, 

Eduardo Jauch

Hey Eduardo Jauch,

You are right but there are lots of javascript code on that page and i cannot remove it. I have to found some work around for that. Thanks for the help.

Regards,

Manish Jawla

Hi Manish,

To set the focus you can add autofocus as an extended property, with value "autofocus", in the input you want to have the focus.

I'm not sure if it will place the cursor caret at the beginning or end, by I think the first.
Than, to put in the end, I think only using JavaScript.

In this case, you will have to study the page to see if a change in the "moment" the JavaScript is executed solves the problem, like put it in a web block or expression, in the end of the page.

Cheers,
Eduardo Jauch