How do addition of no using Javascript ?


Hi

Here is the syntax for doing addition of nos is asp.net

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
    <script type="text/javascript">
        function addNo() {
            var no1 = document.getElementById('<%=txtNo1.ClientID %>').value;
            var no2 = document.getElementById('<%=txtNo2.ClientID %>').value;
            var result = parseInt(no1) + parseInt(no2);
            alert(result);
        }
    
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                No 1</td>
            <td>
                <asp:TextBox ID="txtNo1" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                No2</td>
            <td>
                <asp:TextBox ID="txtNo2" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                <asp:Button ID="btnSubmit" runat="server" OnClientClick='addNo();' Text="Submit" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>

</asp:Content>

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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