Search code examples
prototypejs

Prototype 1.7: Is there a way to serialize elements outside of form?


In Prototype, is there a way to serialize all 'input' elements on the page after looking up using $$? I have to work with some pages that don't have any forms or some elements are outside of form hence cannot use Form.serialize or Form.serializeElements.


Solution

  • Actually you can use Form.serialzeElements() outside of a form you just need to pass it a list of elements.

    For example

    HTML

    <input type="text" name="a" id="a" value="12345" />
    <input type="text" name="b" id="b" value="6789" />
    

    Javascript

    Form.serializeElements($$('input'))
    

    returns

    a=12345&b=6789
    

    try it out in this jsfiddle http://jsfiddle.net/av5Kj/