Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
find sibling input value with jquery in asp.net-mvc

I have a page in my Asp.net mvc projct in Visual studio 2015 where i want to update the user shopping cart with ajax when he changes the quantity of an item. But I have to get the Article Code which is in another input in the same div but i don`t know how to get it. Everything works I just need to Retrieve The Code To Send It To the function "AsyncSauvPanier".

Here is the Ajax Function :

<script>
$('.quantite').change(function () {
    $.ajax({
        url: '@Url.Action("AsyncSauvPanier", "Produits")',
        type: 'post',
        data: {
            quantite: $(this).val(),
            /* I Want to retrieve The Article Code here */
        },
        success: function (result) {
            if (result.status === "Success") {
                $('#nbArticlesPanierlayout').text(result.nbArticlesDansPanier);
            }
        },
        error: function () {
            alert("An error has occured.");
        }
    });
});
</script>

Here Is the Div showing an 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 to look at the sibling function for jquery but I don't quite understand how to use it so any help would be greatly appreciated, tell me if I should try and clarify

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you know if the target will be a preceding sibling you can use .prev().

Description: Get the immediately preceding sibling of each element in the set of matched elements. If a selector is provided, it retrieves the previous sibling only if it matches that selector.

The .siblings() function would work the 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 the input a class you can use that as the filter selector.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!