how to use javascirpt for client side to transfter the values suppose when i enter 2 in textbox1 then in thextbox2 it should show 4 how is it possible because there is no keypress event is there in asp.net texbox control please help

Recommended Answers

All 2 Replies

>there is no keypress event is there in asp.net texbox control

That's true. There is no keypress event with ASP.NET controls but you can attach/add javascript code with ASP.NET controls.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function doSomething() {
            var t1, t2;
            t1 = document.getElementById("TextBox1");
            t2 = document.getElementById("TextBox2");

            no = parseInt(t1.value);
            no = no * 2;

            t2.value = no;
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="return ValidateForm()">
    <asp:TextBox ID="TextBox1" onkeyup="doSomething()" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </form>
</body>
</html>
aspx form coding 
<script language="javascript" type="text/javascript" >
    
    function GetKeyPress()
    {
    document.getElementById('<%=TextBox2.ClientID%>').value=document.getElementById('<%=TextBox1.ClientID%>').value*2
    }
    </script>    
     
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox2" runat ="server" ></asp:TextBox>
        <asp:TextBox ID="TextBox1" onkeyup="GetKeyPress();" runat="server"></asp:TextBox>
    
and that is aspx.cs form coding

protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Attributes.Add("onkeyup", "GetKeyPress()");
        
    }

BUT WHY WE ARE USING THIS CODE >>>>TextBox1.Attributes.Add("onkeyup", "GetKeyPress()"); any help more just in few lines thx

>there is no keypress event is there in asp.net texbox control

That's true. There is no keypress event with ASP.NET controls but you can attach/add javascript code with ASP.NET controls.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function doSomething() {
            var t1, t2;
            t1 = document.getElementById("TextBox1");
            t2 = document.getElementById("TextBox2");

            no = parseInt(t1.value);
            no = no * 2;

            t2.value = no;
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="return ValidateForm()">
    <asp:TextBox ID="TextBox1" onkeyup="doSomething()" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.