Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In asp.net , i have 2 textbox control. In which, i will enter the value and on it key pressed value, i have to display the amount.

Used Javascript function.

On first key press , the event called, but no value is displaying in the second textbox.

On second number key press, showing the value for the first typed number...

I don't understand why on very first time, it is not showing the value eventhough script function is called...

Can anybody guide me to solve this issue

Code

<input type="text" id=txt1 />
<input type="text" id=txt2 />

$('#txt1').keypress(function ()
{
$('#txt2').val()=$('#txt1').val();

});





Thanks.
Posted
Updated 22-Sep-14 19:39pm
v2
Comments
Shemeemsha (ഷെമീംഷ) 23-Sep-14 1:29am    
Which technology you are using for showing the amount..?
And elaborate your question ? are you trying to implement auto complete text box?
Sergey Alexandrovich Kryukov 23-Sep-14 1:29am    
How about showing some minimal but comprehensive code sample to reproduce the problem?
—SA
[no name] 23-Sep-14 1:36am    
show your code where is the problem then we can check that

Try to use onkeyup

ASP Code
ASP.NET
<asp:textbox id="TextBox1" onkeyup="show()" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown"></asp:textbox>


Javascript Code
JavaScript
<script type="text/javascript">
        function show() {
            var txt1 = document.getElementById("TextBox1").value;
            document.getElementById("TextBox2").value = txt1;
        }
</script>



I hope my idea is right. :)
 
Share this answer
 
v2
fiddle for keyup from keyboard[^]

This fiddle will solve your issue i hope. This fiddle shows how on every key press on keyboard the value of entered textbox gets onto the textbox two.
Thanks
Hope this helps
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900