Setting the focus to the last focused text-field
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Founaboui_Haman
Posted On:   Wednesday, January 7, 2004 05:39 AM

Hi all, I am trying to set the focus to the last focused field. I have a dynamically generated jsp page with hundreds of form field. I want that, when a user placed the cursor in a field and when he/she reload the page, the cursor should stayed at the same place. I have a javascript function that gets the name of the focused object, but while trying to call the function (document.formName.selectedField.focus()) , where formName and selectedField are javascript variables, I am getting an undefined error. Another question is how can I save a javascript variable into a java/jsp variable? Does anyone has some idea on how to solve this problem? Please help me. A code shnippet would be appreciated.    More>>

Hi all,


I am trying to set the focus to the last focused field.

I have a dynamically generated jsp page with hundreds of form field. I want that, when a user placed the cursor in a field and when he/she reload the page, the cursor should stayed at the same place. I have a javascript function that gets the name of the focused object, but while trying to call the function (document.formName.selectedField.focus()) , where formName and selectedField are javascript variables, I am getting an undefined error.

Another question is how can I save a javascript variable into a java/jsp variable?

Does anyone has some idea on how to solve this problem? Please help me. A code shnippet would be appreciated.


Lot of thanks in advance

   <<Less

Re: Setting the focus to the last focused text-field

Posted By:   Anin_Mathen  
Posted On:   Wednesday, January 7, 2004 08:17 AM

Founaboui,

There is no direct way of moving your javascript data into java/jsp variable. The solution is to use a trick.


Once you get the name of the field that is focussed on, put that into a hidden field in the form that you are posting. So when you post, the name of the field that was last focussed goes to the server. You can make the server code return the name of the field into a javascript variable using something like



Once you have it in your variable, you can set focus using code like this



Hope this helps.

Anin
About | Sitemap | Contact