<asp:TextBox ID="txtA" data-type="sourceA" runat="server" />
<asp:TextBox ID="txtB" data-type="sourceB" runat="server" />
<asp:TextBox ID="txtResult" data-type="result" runat="server" />
<button onclick="fnaddMethod1(); return false;">Method 1</button>
<button onclick="fnaddMethod2('<%=txtA.ClientID %>', '<%=txtB.ClientID %>', '<%=txtResult.ClientID %>'); return false;">Method 2</button>
<button onclick="fnaddMethod3(); return false;">Method 3</button>
<script type="text/javascript">
// only needed for Method1
var sourceA = '<%=txtA.ClientID %>';
var sourceB = '<%=txtB.ClientID %>';
var resultId = '<%=txtResult.ClientID %>';
</script>
function fnaddMethod1() {
if (typeof (sourceA) == "undefined" || typeof (sourceB) == "undefined" || typeof (resultId) == "undefined")
{
return;
}
var otbA = document.getElementById(sourceA);
var otbB = document.getElementById(sourceB);
var otbres = document.getElementById(resultId);
var v1 = parseInt(otbA.value);
var v2 = parseInt(otbB.value);
otbres.value = v1 + v2;
}
function fnaddMethod2(sourceA, sourceB, targetId) {
var otbA = document.getElementById(sourceA);
var otbB = document.getElementById(sourceB);
var otbres = document.getElementById(resultId);
var v1 = parseInt(otbA.value);
var v2 = parseInt(otbB.value);
otbres.value = v1 + v2;
}
function fnaddMethod3() {
var otbA = $('[data-type="sourceA"]');
var otbB = $('[data-type="sourceB"]');
var otbres = $('[data-type="result"]');
var v1 = parseInt(otbA.val());
var v2 = parseInt(otbB.val());
otbres.val(v1 + v2);
}