Django + JS : value with double curly braces not sent to a JS function. Others are OK [closed]
I display with a loop many shipping services available for a given order on a page containing all my orders.
{% for serv in account.services %}
[...]
<input class="form-check-input" type="radio" name="service{{order.pk}}" value="{{serv.pk}}" ismulti="{{serv.is_multiparcel}}" checked>
[...]
{% if order.weight > serv.max_weight %}
<div class="form-text badge bg-danger" name="weight-alert">Poids commande > max. service {{serv.max_weight}} kg</div>
<script>
disableCheckCauseWeight("service{{ order.pk }}", "{{serv.pk}}");
</script>
[...]
{% endfor %}
One of these services can be selected with a radio button and is identified by 2 prameters : service{{order.pk}}
and {{serv.pk}}
.
Both of them are well displaying in my html code:
<input class="form-check-input" type="radio" name="service639" value="9" ismulti="True" checked="">
Later in my code, for each loop, I call a JS function for disabling the given service if the order's weight is higher than the weight accepted by the service.
But, {{serv.pk}}
isn't sent to disableCheckCauseWeight()
function, despite it's well displayed above in value="{{serv.pk}}"
.
A console log shows well service{{order.pk}}
but not {{serv.pk}}
. I tried with other values like {{order.pk}}
or "tintin" or any other variable, and it's ok.
Why do I have this issue with {{serv.pk}}
?
EDIT :
Here's the JS function called :
function disableCheckCauseWeight(servOrder, servPk) {
console.log(servOrder + servPk);
let service = document.querySelector(`input[name="${servOrder}"][value="${servPk}]"`);
service.checked = false;
service.disable = true;
service.classList.add = 'text-muted'; }