Thursday, 2 February 2017

Sum of TextBox Values on Client Side using JavaScript

On Button Click:-

<html>
<head>
</head>
<body>

<script type="text/javascript">
function Add()
{
var num1=parseInt(document.getElementById("val1").value);
var num2=parseInt(document.getElementById("val2").value);
res=num1+num2;
document.getElementById("result").innerHTML=res;
}
</script>

First Number <input type ="text" id="val1">
Second Number <input type="text" id="val2">
<label id="result"></label>
<br><br>
<span style="margin-left:200px;"><input type="submit" value="Add" id="btn_result" onclick="Add()"></span>
</body>
</html>

output:-









On Text Changes in TextBoxes

<html>
<head>
</head>
<body>

<script type="text/javascript">
function Add()
{
var num1=parseInt(document.getElementById("val1").value);
var num2=parseInt(document.getElementById("val2").value);
res=num1+num2;
document.getElementById("result").innerHTML=res;
}
</script>

First Number <input type ="text" id="val1" onchange="Add()">
Second Number <input type="text" id="val2" onchange="Add()">
<label id="result"></label>
</body>

</html>

output:-









No comments:

Post a Comment

Insert, Delete, Update Using Entity Framework and LINQ in ASP.NET 1> Create Database First 2> Create Table 3> Add ADO...