looping over elements jquery


i wish loop over elements an html form, store values <input> fields an object. following formula doesn't work, though:



function config() {
$("#frmmain").children().map(function() {
var child = $("this");
(child.is(":checkbox"))
this[child.attr("name")] = child.attr("checked");
(child.is(":radio, checked"))
this[child.attr("name")] = child.val();
(child.is(":text"))
this[child.attr("name")] = child.val();
relapse null;
});


neither does following (inspired jobscry's answer):



function config() {
$("#frmmain").children().each(function() {
var child = $("this");
alert(child.length);
(child.is(":checkbox")) {
this[child.attr("name")] = child.attr("checked");
}
(child.is(":radio, checked"))
this[child.attr("name")] = child.val();
(child.is(":text"))
this[child.attr("name")] = child.val();
});
}


the warning always shows child.length == 0. manually selecting elements works:



    
>>> $("#frmmain").children()
object length=42
>>> $("#frmmain").children().filter(":checkbox")
object length=3


any hints loop correctly?



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members