I want to read all page inputs ids and values
into object and pass it to function which loop throuhg them and extract id and value.
I started with:
function send()
{
var data = [];
var inputs = $(":text");
for (var i = 0, l = inputs.length; i < l; i++) {
var input;
input.id = inputs[i].attr("id");
input.text = inputs[i].val();
data[i] = input;
}
receive(data);
}
function receive(data)
{
for (var input in data) {
alert(input.id);
alert(input.text);
}
}
Why this does not work?
For adding items to an array, you likely want to use
.push()instead of accessing it via the numeric index. Also, jQuery provides a.eachto iterate over a set.One more thing. jQuery does include a
.mapfunction, which returns an array “mapped” over a given set which could shorten the above code down to…