Forcing focus after Ajax refresh

Forcing focus after Ajax refresh


I have a page with a set of 3 input texts- Project name, Message and Priority. The Message and Priority fields are disabled by default when the user enters the page. The requirement is that these fields be anabled only after validating the Project name value entered by the user.

I am using the onblur action of the Project name input text and validating the project with an action bound to a hidden button. So my onblur reads something as below:


The button is configured to perform an ajax submit.The action is triggered and the validation action goes through fine.

But I am facing a problem with the focus in the boxes. When I tab out:
- if the validation fails, I require to revert focus to the Project name widget
- if success, then the Message field should get enabled and the focus should move there

I have tried to use a Javascript function as recommended here: .. but it doesnt seem to work. Any inputs on this?


Hi Sathya,

You can try with the RunJavascript action from the HTTPRequestHandler extension.
In the end of your ajax funcion just call RunJavascript with a script like (assuming 8.0+ here): "$('#" + projectNameTextbox.Id + "').focus()"

That said, I'm not big fan of onblur.
Usually it goes against the user expectations to be forcing him to lose focus and/or moving the focus for him.
A good alternative is just to use the builtin on change for that and have cleaner transitions.

For example: (note:in my sample im only accepting "valid name" as a good name, dunno what are your type of validations):
As you can see, in my sample didn't need any extra javascript or hidden elements to present a cleaner transiction.

João Rosado