By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,966 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,966 IT Pros & Developers. It's quick & easy.

How do I insert a char into the textfield on the keydown event of another textfield?

P: 4
How do I insert a char into the textfield on the keypress event of another textfield?

I have two textboxes, "text1" and "text2".

[COLOR=DarkRed]Important:[/COLOR]
"text1" is outside the table.
"text2" is inside the table cell.

On the keydown/keypress/keyup event of "text1", the character which I entered in the "text1" must display in the textfield "text2".

Sample Code:
[HTML]<input type="text" name="text1" onkeypress="write(this)">
<table> //This is a dynamically generated table
<tr>
<td><input type="text" name="text2"></td>
</tr>
</table>
[/HTML]
For example,
Suppose If I enter srsh in "text1", "text2" should display the same.
At the same time, If I enter 'u' in between 's' and 'r' and 'e' in between 'r' and the second 's' in "text1", "text2" should now display "suresh".

And I want to know one more thing?
How can I get the position of the cursor of the textfield "text1"?
How can I set the position of the cursor of the textfield "text2"?

Can anyone please help me?

Regards,
Suresh.
Oct 24 '05 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Just set the value of the first text box to the second one:
Expand|Select|Wrap|Line Numbers
  1. var form = text1.form;
  2. var text2 = form.text2;
  3. text2.value = text1.value;
Oct 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.