Gareth,

http://www.prototypejs.org/api/array/first
and
http://www.prototypejs.org/api/array/last
should do the trick.

The problem arises when you need to access next element in a
collection. Consider this example:

$$('input[type=text]').invoke('observe', 'keypress', function(e) {
  if (Event.KEY_TAB == e.keyCode) {
    // focus next element in collection
  }
})

Inside a callback we could resort to this.next('input[type=text]'),
but this unfortunately will not work if input elements are not in a
linear order
One way to make it happen is by storing index of a current element in
a closure and focusing the element with index = index + 1 when the key
is pressed

$$('input[type=text]').each(function(el, index) {
  el.observe('keypress', function(e)) {
    if (Event.KEY_TAB == e.keyCode) {
      $$('input[type=text]')[index+1].focus()
    }
  }
})


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to