I want to make a section with goods in which you can "+" and "-" increase or decrease the quantity of goods And then, depending on the amount, "sell" it.
Now we need to pass the value {{ el.id }} to django views
My code: html:
<form method="POST">
{% csrf_token %}
{% for el in form3 %}
{% if el.count > 0 %}
[ {{ el.count }}шт. ] <br>
[ {{ el.title }} ]<br>
<a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
<span id="value{{ el.id }}">0</span>
<a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
<br>
Function where i + or - from count
<script>
$(function(){
var valueElement = $('#value{{ el.id }}');
function incrementValue(e){
valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
return false;
}
$('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
$('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
});
</script>
{% endif %}
{% endfor %}
</form>
how can i get the values with "span id=value{{ el.id }}"
Solved
{% for el in form3 %}
{% if el.count > 0 %}
[ {{ el.count }}шт. ] <br>
[ {{ el.title }} ]<br>
<a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
<span id="span-value{{el.id}}">0</span>
<a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
<br>
<input type="hidden" name=name-{{el.id}} id="input-{{el.id}}" value="0">
<script>
$(function(){
var valueElement = $('#span-value{{el.id}}');
function incrementValue(e){
valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
var value = $("#span-value{{el.id}}").text();
var lower=$("#input-{{el.id}}").val(value);
return false;
}
$('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
$('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
});
</script>
{% endif %}
{% endfor %}
use this for copy\\duplicate span value on input After this you can user request.post.dict or request.post.items() for key:values
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.