• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

SetFocus on re-displayed page

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp page that has many calculate buttons. Hitting any of these would submit the form, do some calculations, repopulate the page with the new values and redisplay it. But my OnLoad sets focus to the first element.
How can I keep track of which button was hit, and setfocus to that button.
Somebody pls help. Thx.
[ February 24, 2004: Message edited by: Michelle Cox ]
Posts: 15385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it could be many buttons that would do the submission, you need to send a value to the jsp and back to the document when it is being reloaded.
That value should be the button name.
How can you keep track of that button name that was clicked you may ask?
The easiest way would be to add the value to a hidden form element when it is clicked.
now when the form gets submitted you have the ability to keep track of what was submitted. now when the page gets reloaded, you need to pass that button value back to the page somehow. It can be anything from query string to filling in a hidden field.
With that information you need to call the focus()
That is a lot of work to focus a button. Another route would be with cookies. Storing the value into a cookie and reading the cookie when the page is loaded.
Hope you can follow my gibberish
Michelle Cox
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your detailed reply. I am able to follow what you are saying.
But one thing that I didn't mention bcz I don't know if it is important or not is: I am using struts/dynabeans/tiles/...
So, right now my html:form is like this.
<html:form action="/PersonalInfoSubmit" focus="firstName">
Can the focus property be somehow used to handle this scenario, or should I start modifying my <body OnLoad.. > (which is located in my tiles-layout)
To the moderators of this forum: Should we maybe move this thread to the Struts forum? I am sorry if I posted it in the wrong place, bcz I didn't quite understand if this would be a Javascript solution or not.
Thanks again.
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also have a similar requirement. Were you able to get a solution for your problem?
And for me, 'focus' wont really work, because not only do I need set focus to that field/button, I also have to scroll the page down, so that, that section is visible to the user. But 'focus' doesnt do that.
A friend suggested the use of anchor tags to scroll the page, and using them somehow to roll the page down to the desired section. Please let me know your findings.
A Ramk.
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!