input collection function for AJAX

handgestrickt wrote a function that collects input-field content by a given regular expression of the id. we needed it beside the $F()- and Form.serialize()-function provided by Prototype.js . unfortunately it provides no function to make an associative array of the input-fields' names and values. here is the code:

var foo = {
        getInputsByFragment: function(element,fragment) {
                var result = {};
                var inputs = $(element).getElementsByTagName('input');
                for(var a=0;a<inputs.length;a++) {
                        if(
                                inputs[a].id.search(fragment) != -1 &&
                                inputs[a].value != ''
                        ) result[inputs[a].id.replace(fragment,'')] = inputs[a].value;
                }
                return result;
        }
}

usage:

foo.getInputsByFragment('contactform',/^contact_/);

feel free to use it. did a great job for us!

Tuesday, 06. March 2007 • trackback url

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title:
Your Name:
Email Address:
Make Public?
Website:
Make Public?

Comment:


Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.


Captcha:

captcha image

please type the content of the above image into the following form-field: