2

I have an input element with id billing:postcode. The Prototype $() selector is unable to select this element as described in this ticket.

I found this solution for the same problem in jQuery. I can't get it to work in Prototype. I tried:

var element = document.getElementById('billing:postcode');
Element.extend(element);
element.invoke(...);

and:

var element = document.getElementById('billing:postcode');
$(element).invoke(...);

Both don't work: Uncaught TypeError: Object #<HTMLInputElement> has no method 'invoke'

I know I can get the element with the CSS selector like this:

$$('#billing\\:postcode')

But I want to use getElementById

Community
  • 1
  • 1
i.amniels
  • 1,781
  • 1
  • 25
  • 37

1 Answers1

3

Your Element.extend(element); works, although the most common way is to just pass it through $():

var extended = $(document.getElementById('billing:postcode'));

But note that single elements don't have the Prototype invoke method, which is the real problem you're running into. :-) invoke is part of Enumerable, which only applies to lists of elements, not individual ones — its purpose is to call a given function on each element in the list. Rather than calling invoke, just call the function you're trying to invoke directly.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875