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 ]
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. onclick="document.formName.HiddenName.value=this.name"; 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() document.FormName[ButtonName].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 Eric
posted 15 years ago
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. Thanks 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: