How can i get value from the nested textbox with same class?


#1

Example i have two text box:

<input type="text" class="amount" >
<input type="text" class="amount" >

#2

Can you post some more code? Are those input boxes each in an individual template?


#3

If you’re trying to get all values from all inputs with same class, you could do it like this :

$( ".amount" ).val(function(index, value){
     // do what you need with those values here
})

#4

@shad I try to use jquery like that but it sometime not work properly when no refresh page.


#5

this is my code. actually this code is work. but it sometime calculate with the wrong value when there is no refresh page for about 30 minutes or more.

total = 0 ;
  $('.amount').each ->
     total += parseFloat $(this).val()

#6

Can you elaborate ? How do you trigger it ?


#7

it lookis like the picture below. I just want to iterate all the amount and calculate then put it into subtotal and total.
this is my code:

total = 0 ;
  $('.amount').each ->
    total += parseFloat $(this).val()
  console.log(total)
  $('[name="subtotal"]').val(roundKhr(total))
  $('[name="total"]).val(roundKhr(total))


#8

Don’t know how your code looks like behind, but you could simply trigger your calculations function each time the amount change in one of your row.


#9

Actually that code is worked properly. but it just sometime calculated wrong. Anyway thanks so much. i will try to firgure out more.