My template code is as follows
{% for content in contentlist %}
<div class="card card-margin-top">
<div class="card-body">
<div class="card-head">
<p class="card-title">PRICE ‐
<span id="price">{{content.price}}</span>
</p>
</div>
</div
</div>
{% endfor %}
and I want to convert my price value into a comma-separated value using the js function. JS function is as follows
window.onload=function(){
var price = document.getElementById("reservedPrice").innerText
x = updateTextInput(price)
document.getElementById("reservedPrice").innerText = x
}
function updateTextInput(val) {
x = val.toString();
var lastThree = x.substring(x.length-3);
var otherNumbers = x.substring(0,x.length-3);
if(otherNumbers != '')
lastThree = ',' + lastThree;
var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
return res
}
but in result looks like this. JS executing only on first entry. I want all prices to be comma-separated.