hi everyone, i am using Django for loop in the template to out put some items an i added the {{forloop.counter}} to the id attribute.
{% for item in products %}
<label class=" update-cart">
<input type="checkbox" id="ref_prod{{forloop.counter}}" onclick="myFunction" >
<span class="slider round pt-2"></span>
</label>
<script>
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("ref_prod{{forloop.counter}}");
alert(ref_prod{{forloop.counter}})
}
<script>
{% endfor %}
when i tried this no matter the counter number it keeps alerting “ref_prod1”.
i need it to be able to get something like “ref_prod1”., “ref_prod2” “ref_prod3” etc.