i have page in asp.net mvc projct in visual studio 2015 want update user shopping cart ajax when changes quantity of item. have article code in input in same div don`t know how it. works need retrieve code send function "asyncsauvpanier".
here ajax function :
<script> $('.quantite').change(function () { $.ajax({ url: '@url.action("asyncsauvpanier", "produits")', type: 'post', data: { quantite: $(this).val(), /* want retrieve article code here */ }, success: function (result) { if (result.status === "success") { $('#nbarticlespanierlayout').text(result.nbarticlesdanspanier); } }, error: function () { alert("an error has occured."); } }); }); </script>
here div showing item :
<div style="margin: 10px; position: absolute; left: 600px; top: 140px;"> @if (session["hideqte"].tostring() != "true") { <p> <b>panier</b> </p> <input style="display: none;" class="codearticle" type="text" name="codearticle" value="@model.code_art" /> <input style="max-width: 50px; text-align: right;" class="quantite" type="number" name="quantite" ng-model="quantite_@model.code_art" min="0" ng-init="quantite_@model.code_art=@pc.getquantiteactuelleproduitdanspannier(model.code_art, uniteadmin)" required /> <span>{{prix_@model.code_art * quantite_@model.code_art | number:2}} $</span> } </div>
i tried @ sibling function jquery don't quite understand how use appreciated, tell me if should try , clarify
if know if target preceding sibling can use .prev().
description: preceding sibling of each element in set of matched elements. if selector provided, retrieves previous sibling if matches selector.
the .siblings() function work same way.
<div> <input name="codearticle" type="hidden" value="@code" class="codearticle" /> <input name="quantite" type="text" value="" class="quantite" /> </div> $(".quantite").on("change", function(e) { ... var selector = ".codearticle"; var codearticle = $(this).prev(selector).val(); });
since you've given input class can use filter selector.
Comments
Post a Comment