• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to send the user back to a field on a long form

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In our application, we have a couple hundred HTML pages with many controls on each one.

The request has come in to be able to be able to return the focus back to the last field the user was editing after, say, he clicks "save and continue".

Because there are so many fields on our HTML forms, the users cannot seem to remember which field they were editing.

Is there a simple way to do this return to the last edited field, or would something like the below work better:

// save the field name we just lost focus from...
var allElments = document.getElementById('*');
for (var i = 0; allElements.length; i++)
{
// loop through and assign to a function to remember the field name when focus leaves the field.
addEventHandler(document.getElementById(allElements[i]), "blur", saveFieldName); // need to create saveFieldName function
}

// add other code to restore the focus...

====

Look forward to any replies.

-- Mike
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why all the looping? Just establish one blur handler on the form.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Why all the looping? Just establish one blur handler on the form.



The looping was to assign each field on the form to the one blur event handler.

Correct?

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Just establish one blur handler on the form.


Why does there need to be a handler on each control when just one will do?
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But wouldn't you need to assign the onBlur() event to some function for every control on the form?

Would you do that assignment in a loop?

Perhaps I'm missing your point.

Thanks Bear!

 
Bear Bibeault
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike London wrote:But wouldn't you need to assign the onBlur() event to some function for every control on the form?


No. Why? A single event handelr on the form can handle the blur event of all its children.

Perhaps I'm missing your point.


I think you are.

I forget if you are one of the posters who has my jQuery book. If so, read the first section of chapter 4 which describes how events work in the browsers without jQuery.

If not, look up "event bubbling". It's needless to put the same event handler on multiple form controls when you can just do it once.
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic