How to change variable inside twig in javascript

I want to change the variable inside Twig by javascript, but there is an error: Variable "max" does not exist.

my twig:

{% block body %}
<label for="maxN">Niveau MAX</label>
<input type="number" id="maxN" class="form-control">

{{ form_label(form.ncUoCommandeUo) }}
{{ form_widget(form.ncUoCommandeUo, {'attr':{'min':1, 'max': max}}) }}
{% endblock %}

{% block javascripts %}
<script>

my.ajax......

if (ncMaxUo.val() === 1) {max = 1;
}elseif(ncMaxUo.val() === 2) {max = 2;
}elseif(ncMaxUo.val() === 3) {max = 3;
} else {max = 4;
}
....
</script>
{% endblock %}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *