1👍
✅
After some discussion, your question is now clear. You must use jQuery change
event for your select tag.
Change your script to:
$('.inp select.item').change(function() {
let elm = $(this);
$.ajax({
url:'/ajax/price_validate/',
data:{
// elm.attr("name"): elm.val()
// OR keep it simple
"item_id": elm.val()
},
success:function(data){
if (data.price){
elm.closest("div.inp").find("input.price").val(data.price);
}
else{
alert('price doesn't provided')
}
}
})
})
views.py:
@login_required
def check_price(request):
query = request.GET
data = {
'price': Item.objects.get(id=query.get("item_id")).price,
}
return JsonResponse(data)
👤NKSM
Source:stackexchange.com