I am trying to iterate through all form elements with id that begins with a specified prefix and create an xml string with results, but it is getting a bit complicated as forms form input types seem to have different behaviors . Does this functionality already javascript, jQuery or third party jQuery module?
function fnPreIterate(){
var XMLstring;
$(':input[id*="f1"]').each(function() {
XMLstring += (" <" +this.name+ '>' + this.value + "</" + this.name + "> " );
});
$('#XMLstring').html("<pre>" + fnEncodeEntities(string) + "</pre>");
};
If you use:
instead of
you’ll save a lot of headaches with difference in form elements.
Another way to iterate is to use
.serializeArray():Hope this helps. Cheers
PS: To select by prefix, you should do
$(':input[id^="f1"]')(use ^ instead of *)