question

MiguelBT-9804 avatar image
0 Votes"
MiguelBT-9804 asked MiguelBT-9804 edited

Jquery calculation values per row

Hi, I don't know if it's correct but how is it an MVC project.


I have a jquery that performs an account when entering a value.

 $(document).on("change keyup blur", "#startValue", function () {
             var main = @ViewBag.sumMin;
             var disc = $('#startValue').val();
             var mult = (main * disc).toFixed(2);
             $('#result').val(mult);
         });

the previous code working
174446-calc.gif

my structure
174420-image.png

I also intended to do this account with a value in each row of a table
i try this:

UPDATE (for some reason I can't insert the code in format (permission error any help?)

174419-image.png

I tried closing the rows but without success, does it work through a cycle going through the IDs.
Thanks for all help.



dotnet-aspnet-mvc
calc.gif (111.8 KiB)
image.png (8.0 KiB)
image.png (37.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sreejukg avatar image
0 Votes"
sreejukg answered

if you do the keyup event on document, the "this" object refer to the document. so if you want this to be for each table row or cell, do the event on corresponding element.

$(".your table row class").on("change keyup blur", "#startValue", function () {
var disc = $('#startValue').val();
var numpec = $(this).closest('tr').find("#numpec").val();
var multi = (numpec * disc).toFixed(2);
$(this).closest('tr').find("#resultTR").val(multi);
});

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered

Hi @MiguelBT-9804,
I think it should be the problem written in $(this).closest('tr').find, maybe you can provide more detailed code.

 <td >
   <input type="text"" />
 </td>

Replace

 $(this).closest('tr').find("#resultTR").val(multi);

Should be

  $(this).closest('tr').find('input[type="text"]').val(multi);

Best regards,
Lan Huang


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.