0

enter image description here

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;
});

4 Answers 4

1

ES6 template literals or string concatenation. Pick one.

$(`#po_am_${o}`)

$('#po_am_' + o)
Sign up to request clarification or add additional context in comments.

Comments

1

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>"));
});

Comments

0

you can. with string interpolation.

$(`#po_am_${o}`)

Comments

0
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;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.