<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jQuery1.aspx.cs" Inherits="jQuery1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>How to read TextBox value using JQuery</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="txtFirst"></asp:TextBox>
<asp:TextBox runat="server" ID="txtSecond"></asp:TextBox>
<asp:Button runat="server" ID="btn" Text="+" />
<asp:TextBox runat="server" ID="txtSum"></asp:TextBox>
</div>
</form>
</body>
</html>
<script language="javascript">
$(document).ready(function() {
$('#btn').click(function() {
// Read First number & 2nd Number from TextBox
var $nFirstNum = parseInt($('#txtFirst').val())
var $nSecondNum = parseInt($('#txtSecond').val())
var $nResult = $nFirstNum+$nSecondNum
// Set the result into txtSum TextBox
$('#txtSum').val($nResult)
return false;
});
});
</script>
No comments:
Post a Comment