JavaScript Count input values jquery count input values,how to count input values in

I would like to count values inserted into a form without refreshing the page. The below code works well if all of the inputs have "name='test'" set the same but I need name to be unique to process the form once its submitted using php.

Does anyone know how I can get the input values using "id='count'" with javascript/jquery?

Thanks in advance for your help.

e.g.

function findall() {
  var array = document.getElementsByName('price_no_vat');
  var total = 0;
  for (var i = 0; i < array.length; i++) {
    if (parseInt(array[i].value))
      total += parseInt(array[i].value);
  }
  document.getElementById('3').value = total;
}
<input id="1" name="price_no_vat" onblur="findall()">
<input id="2" name="VAT" onblur="findall()">
<input id="3" mame="all" disabled>
Answer:1

You can specify a common class, then Document.querySelectorAll() can be used with Class Selector.

Returns a list of the elements within the document (using depth-first pre-order traversal of the document's nodes) that match the specified group of selectors.

function findall() {
  var array = document.querySelectorAll('.cls');
  var total = 0;
  for (var i = 0; i < array.length; i++) {
    if (parseInt(array[i].value))
      total += parseInt(array[i].value);
  }
  document.getElementById('3').value = total;
}
<input id="1" name="price_no_vat" class='cls' onblur="findall()">
<input id="2" name="VAT" class='cls' onblur="findall()">
<input id="3" name="all" disabled>
Answer:2

$('#1).val(); will show you the value of the id="1"

If you want to get all of them

 $.each('input', function(idx, obj) {
     console.log($(obj).val());
     //you can set a counter, and add items, you can push it into an array,
     //you can write condition here, etc...
 });
Answer:3

$(function () {
    $("input").blur(function () {
        $("#3").val(function () {
            var i1 = 0;
            $("[name='price_no_vat']").each(function (index, element) {
                i1 += parseFloat(element.value) || 0;
            });

            var i2 = parseFloat($("#2").val()) || 0;
            return i1 + i2;
        });
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="1" name="price_no_vat" />
  <input id="12" name="price_no_vat" />
<input id="2" name="VAT" />
<input id="3" mame="all" disabled />
Answer:4

In Aurelia application I have a "Rename" form with a single input <input ... value.bind="something.name" /> and two buttons: Save and Cancel. The same something object is already used in ...

In Aurelia application I have a "Rename" form with a single input <input ... value.bind="something.name" /> and two buttons: Save and Cancel. The same something object is already used in ...

I have a value from JavaScript: var customerID = document.getElementById("CustomerID").value; Now I want query the firstName, lastName from module data, based on that customerID variable. {...

I have a value from JavaScript: var customerID = document.getElementById("CustomerID").value; Now I want query the firstName, lastName from module data, based on that customerID variable. {...

  1. pass javascript variable to php
  2. pass javascript variable to html
  3. pass javascript variable to c#
  4. pass javascript variable to python
  5. pass javascript variable to razor
  6. pass javascript variable to php function
  7. pass javascript variable to flask
  8. pass javascript variable to url.action
  9. pass javascript variable to django
  10. pass javascript variable to css
  11. pass javascript variable to jinja2
  12. pass javascript variable to ruby
  13. pass javascript variable to django url
  14. pass javascript variable to sql query
  15. pass javascript variable to asp classic
  16. pass javascript variable to python flask
  17. pass javascript variable to another html page
  18. pass javascript variable to django template
  19. pass javascript variable to mvc controller
  20. pass javascript variable between pages

I want to use jQuery to look for some text and it exists I want to hide it. So if : Yes exists it should be hidden. HTML: <div class="listing_detail col-md-4"><strong>Living Room:</...

I want to use jQuery to look for some text and it exists I want to hide it. So if : Yes exists it should be hidden. HTML: <div class="listing_detail col-md-4"><strong>Living Room:</...

  1. hide search text in datatable
  2. jquery datatable hide search text box
  3. hide text search

I have an image in the center of my webpage. Once the user scrolls and the image hits the top of the window, I am attempting to fix the image to the top of the page so that it scrolls with the page. ...

I have an image in the center of my webpage. Once the user scrolls and the image hits the top of the window, I am attempting to fix the image to the top of the page so that it scrolls with the page. ...