Reputation: 219
Is there a way to implement variable 'o' instead of '1' in #po_am_1 ? Thank you.
var pondeli_in = [];
var o = 0;
$('input[name="pondeli"]:checked').each(function () {
pondeli_in.push(($(this).attr('value')) + (' (') + ($('#po_am_1').val()) + ('x)') + ("<br>"));
o += 1;
});
Upvotes: 0
Views: 54
Reputation: 4659
var pondeli_in = [];
var o = 0;
$('input[name="pondeli"]:checked').each(function () {
pondeli_in.push(($(this).attr('value')) + (' (') + ($('#po_am_'+o).val()) + ('x)') + ("<br>"));
o += 1;
});
Upvotes: 0
Reputation: 1234
you can avoid using an extra variable for index
var pondeli_in = [];
$('input[name="pondeli"]:checked').each(function (i, el) {
pondeli_in.push(($(el).attr('value')) + (' (') + ($('#po_am_' + i).val()) + ('x)') + ("<br>"));
});
Upvotes: 1
Reputation: 11297
ES6 template literals or string concatenation. Pick one.
$(`#po_am_${o}`)
$('#po_am_' + o)
Upvotes: 1