How to solve the Total of my html code that linking with input type = "number"

Yen

<!DOCTYPE html>
<html>
<body>
 <form name="TESTING">
   <h1>Menu</h1>
   <fieldset style="width:240px">
	  <legend>Side order</legend>
<table>
        <thead>
          <tr>
            <td></td>
            <td>Qty</td>
            <td>Price</td>
            <td>Total</td>
          </tr>
        </thead>
     
        
<tr>
          <td>Chicken Wings</td>\
          <td><input type="number" name="a" id="input" value="0" onchange="calculate();"/></td>
          <td> 2.50</td>
          <td><output type="number" name="x" id="output"></output></td>
          

</tr>

<tr>
          <td>Spaghetti</td>
          <td><input type="number" name="b" id="input" value="0" onchange="calculate();"/></td>
           <td> 8</td>
          <td><output type="number" name="y" id="output"></output></td>

</tr> 



 <tr>
          <td>Garlic Bread</td>
          <td><input type="number" name="c" id="input" value="0" onchange="calculate();"/></td>
          <td> 2</td>
          <td><output type="number" name="z" id="output"></output></td>

</tr> 

</table>
</fieldset>

<fieldset style="width:240px">
	  <legend>Drink order</legend>
<table>
        <thead>
          <tr>
            <td></td>
            <td>Qty</td>
            <td>Price</td>
            <td>Total</td>
          </tr>
       </thead>
     
        
<tr>
          <td>Coke</td>\
          <td><input type="number" name="d" id="input" value="0" onchange="calculate();"/></td>
          <td> 2</td>
          <td><output type="number" name="e" id="output"></output></td>
          

</tr>



<tr>
          <td>Mineral Water</td>
          <td><input type="number" name="f" id="input" value="0" onchange="calculate();"/></td>
           <td> 1.50</td>
          <td><output type="number" name="g" id="output"></output></td>

</tr> 



 <tr>
          <td>Cofee</td>
          <td><input type="number" name="h" id="input" value="0" onchange="calculate();"/></td>
          <td> 3.50</td>
          <td><output type="number" name="i" id="output"></output></td>


</tr> 


<tr>
    <td>total = </td>
    <td><output type="number" name="finaltotal" id="output"></output></td>
</tr>




</table>
</fieldset>

</form>
<script type="text/javascript">
    function calculate() {
        var USERINPUT1 = document.TESTING.a.value,
            RESULT = USERINPUT1* 2.50;
        document.TESTING.x.value = RESULT;
        
        var USERINPUT2 = document.TESTING.b.value,
            RESULT = USERINPUT2* 8;
        document.TESTING.y.value = RESULT;
       
        var USERINPUT3 = document.TESTING.c.value,
            RESULT = USERINPUT3* 2;
        document.TESTING.z.value = RESULT;
     
        var USERINPUT4 = document.TESTING.d.value,
            RESULT = USERINPUT4* 2;
        document.TESTING.e.value = RESULT;
      
        var USERINPUT5 = document.TESTING.f.value,
            RESULT = USERINPUT5* 1.50;
        document.TESTING.g.value = RESULT;
        
        var USERINPUT6 = document.TESTING.h.value,
            RESULT = USERINPUT6* 3.50;
        document.TESTING.i.value = RESULT;
    
      document.TESTING.finaltotal.value = ((document.TESTING.i.value) +       (document.TESTING.g.value) + (document.TESTING.e.value) + (document.TESTING.z.value)   + (document.TESTING.y.value) + (document.TESTING.x.value));

}	

</script>
</body>
</html>

The total got problem...it is like 000000..if i choosing the first item...then it is 000002.5...first 2.5 become to the last position...i have no idea how to solve this...if you guys know how to solve please help me...i will very appreciate..THANKS.

dfsq

You need to cast string input values for numbers, otherwise unary + operator works like cancatenation operator for strings. Fix it something like this:

var form = document.TESTING;
form.finaltotal.value = Number(form.i.value) + 
                        Number(form.g.value) + 
                        Number(form.e.value) + 
                        Number(form.z.value) + 
                        Number(form.y.value) + 
                        Number(form.x.value);

Remember that input value you get with value property is always a string, not a number. And result of + operation is always a concatenated string again if at least one of the operands is a string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to solve the Total of my html code that linking with input type = "number"

From Dev

How to Input a Number that changes Total

From Dev

HTML how to set value of <input type="number"> to infinity

From Dev

How to display the total number of quantity in the input box

From Dev

How to efficiently track the total number of lines of code in my Ruby on Rails project on Cloud9 IDE?

From Dev

How can i solve my code to check size of data type (is c language with gcc compiler) on linux mint

From Dev

How to solve SonarQube complaints about my code?

From Dev

How to solve SonarQube complaints about my code?

From Dev

My html and css are not linking ( i have searched everything and i cant solve this)

From Dev

Display of units in HTML stepper <input type="number">

From Dev

"maxlength" is not working with input type="number" in html textbox

From Dev

Html5 input type number formatting

From Dev

Editable units in HTML <input type=“number”>

From Dev

"maxlength" is not working with input type="number" in html textbox

From Dev

How to use awk to count the total number of input lines in a file?

From Dev

HTML5 input pattern not working in input type="number"

From Dev

How can i add the random number to my total for java(blackjack)?

From Dev

How to count the total number of the opened files by the users and processes on my machine

From Dev

How to get total number of likes on my page through facebook api

From Dev

How to count the total number of the opened files by the users and processes on my machine

From Dev

How to solve 'Undefined Index' Error from <input type="radio">?

From Dev

How to solve invalid input syntax for type double precision

From Dev

How to format a input type number field with currency

From Dev

How to validate input type="number" in ReactJS?

From Dev

How to retrieve data entered in input type ="number"?

From Dev

How to block +,-,e in input type Number?

From Dev

How to set maximum length in input type=number?

From Dev

How to get and print input type number with jQuery?

From Dev

How to autodelete comma from input type number

Related Related

  1. 1

    How to solve the Total of my html code that linking with input type = "number"

  2. 2

    How to Input a Number that changes Total

  3. 3

    HTML how to set value of <input type="number"> to infinity

  4. 4

    How to display the total number of quantity in the input box

  5. 5

    How to efficiently track the total number of lines of code in my Ruby on Rails project on Cloud9 IDE?

  6. 6

    How can i solve my code to check size of data type (is c language with gcc compiler) on linux mint

  7. 7

    How to solve SonarQube complaints about my code?

  8. 8

    How to solve SonarQube complaints about my code?

  9. 9

    My html and css are not linking ( i have searched everything and i cant solve this)

  10. 10

    Display of units in HTML stepper <input type="number">

  11. 11

    "maxlength" is not working with input type="number" in html textbox

  12. 12

    Html5 input type number formatting

  13. 13

    Editable units in HTML <input type=“number”>

  14. 14

    "maxlength" is not working with input type="number" in html textbox

  15. 15

    How to use awk to count the total number of input lines in a file?

  16. 16

    HTML5 input pattern not working in input type="number"

  17. 17

    How can i add the random number to my total for java(blackjack)?

  18. 18

    How to count the total number of the opened files by the users and processes on my machine

  19. 19

    How to get total number of likes on my page through facebook api

  20. 20

    How to count the total number of the opened files by the users and processes on my machine

  21. 21

    How to solve 'Undefined Index' Error from <input type="radio">?

  22. 22

    How to solve invalid input syntax for type double precision

  23. 23

    How to format a input type number field with currency

  24. 24

    How to validate input type="number" in ReactJS?

  25. 25

    How to retrieve data entered in input type ="number"?

  26. 26

    How to block +,-,e in input type Number?

  27. 27

    How to set maximum length in input type=number?

  28. 28

    How to get and print input type number with jQuery?

  29. 29

    How to autodelete comma from input type number

HotTag

Archive