I do have many DIVs with the same class .list
. They are filled with other divs with the ID element
. In these element
divs there a checkboxes and textfields. I'm able to get all the checked checkboxes' next Textfield's value. I've saved them into one Array but I want an Array for each .list
.
That's how my Code looks so far:
function test(){
var array = new Array();
$(".list > #element").each(function(){
array.push($(this).find('input:checkbox[class=unterpunkte]:checked').next('input[type=textfield]').val());
});
console.log(array);
}
How can I dynamcially creat an Array for each list. I don't want to have one Array where all the Values are saved. I need Arrays for each div with class .list
. Any ideas?
HTML/PHP:
echo("<div class='list' name='$oberpname' value='$oberpname'>");
while($satz != null)
{
echo("<div id='element'><label><input type='checkbox' class='unterpunkte' name='$satz[unterpname]' value='$satz[unterpid]'><input type='textfield' class='$oberpname' value='$satz[unterpname]' readonly/></label></div>");
$satz=mysql_fetch_assoc($cursor);
}
echo("</div>"); //.list div end
EDIT NOTE: Added HTML/PHP
I do have many DIVs with the same class .list
. They are filled with other divs with the ID element
. In these element
divs there a checkboxes and textfields. I'm able to get all the checked checkboxes' next Textfield's value. I've saved them into one Array but I want an Array for each .list
.
That's how my Code looks so far:
function test(){
var array = new Array();
$(".list > #element").each(function(){
array.push($(this).find('input:checkbox[class=unterpunkte]:checked').next('input[type=textfield]').val());
});
console.log(array);
}
How can I dynamcially creat an Array for each list. I don't want to have one Array where all the Values are saved. I need Arrays for each div with class .list
. Any ideas?
HTML/PHP:
echo("<div class='list' name='$oberpname' value='$oberpname'>");
while($satz != null)
{
echo("<div id='element'><label><input type='checkbox' class='unterpunkte' name='$satz[unterpname]' value='$satz[unterpid]'><input type='textfield' class='$oberpname' value='$satz[unterpname]' readonly/></label></div>");
$satz=mysql_fetch_assoc($cursor);
}
echo("</div>"); //.list div end
EDIT NOTE: Added HTML/PHP
Share Improve this question edited Feb 27, 2014 at 8:05 Raviranjan Mishra 8572 gold badges11 silver badges26 bronze badges asked Feb 27, 2014 at 7:59 PreprocezzorPreprocezzor 3071 gold badge6 silver badges17 bronze badges 9- please provide the html – Anoop Joshi P Commented Feb 27, 2014 at 7:59
- 2 IDs must be unique, by definition. – elclanrs Commented Feb 27, 2014 at 8:02
- @Preprocezzor:you should provide rendered html – Anoop Joshi P Commented Feb 27, 2014 at 8:06
- Can you explain me the difference between a rendered html and my html? – Preprocezzor Commented Feb 27, 2014 at 8:08
-
textfield
is not a valid input type. – elclanrs Commented Feb 27, 2014 at 8:11
1 Answer
Reset to default 4Note: ID of an element must be unique, so instead of using element
as an ID use it as a class.
You can create an array of arrays, and access the desired list of checkboxes using the index of the list
element lik
function test() {
var array = new Array();
$(".list").each(function () {
var vals = $(this).find('input:checkbox[class=unterpunkte]:checked').next('input[type=textfield]').map(function () {
return this.value;
}).get();
array.push(vals)
})
console.log(array);
}
Now array[0]
will give the values for list 1 where as array[1]
will give the values for list 2