Example : How to add two values and display the result [Addition of two values].
<!DOCTYPE html>
<html>
    <head>
        <title>Addition of two values</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script>
	   var first="";
	   var second="";
	   var TA="";
           //var first="", second="", TA="", Total;
			
	   function enter1()
	    {
		var x=event.keyCode||event.which;
		if(x===13)
		{
		   first=document.form1.Txt1stValue1.value;
		   event.preventDefault();
		   document.form1.Txt2ndValue1.focus();						
		}
	     }
			   
	   function enter2()
	    {
		var x=event.keyCode||event.which;
		if(x===13)
		{
		   second=document.form1.Txt2ndValue1.value;
		   event.preventDefault();
		   document.form1.TxtValue1.focus();
						
		   TA=parseInt(first)+parseInt(second);  
		   document.form1.TxtValue1.value=TA;
		}
	     }
       </script>     
    </head>
    <body>
        <form name="form1">
           <table> 
	     <tr>
		<td>1st value</td>
		<td>:</td>
	        <td>
		   <input type="text" autofocus="" name="Txt1stValue1" id="Txt1stValue2" 
                       onkeypress="enter1()" style="padding:2px; border-radius: 4px" 
                       placeholder="Enter First Value">
		</td>
	      </tr>
			   
	      <tr>
		<td>2nd value</td>
		<td>:</td>
		<td>
		   <input type="text" name="Txt2ndValue1" id="Txt2ndValue2" onkeypress
                    ="enter2()" style="padding:2px; border-radius: 4px" placeholder=
                    "Enter Second Value">
	        </td>
	      </tr>
				
	      <tr>
		<td>Sum Total value</td>
		<td>:</td>
		<td>
		   <input type="text" readonly="" name="TxtValue1" id="TxtValue2"  
                    style="padding:2px; border-radius: 4px" placeholder="The Result is">
		</td>
	      </tr>
            </table>
        </form>                     
    </body>
</html>

 442 total views,  1 views today


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.