Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting text at the cursor when key pressed

Status
Not open for further replies.

COMPAQ

Programmer
Dec 13, 2000
4
0
0
SG
Hello,

How can we insert text (&quot;<li>&quot;) at the cursor when some one press EnterKey.

Ex:

Text: This is wonderfull

suppose cursor is located after &quot;is&quot; and before &quot;wonderfull&quot; and when we press &quot;ENTER&quot; <li> should appear after &quot;is&quot; and before &quot;wonderfull&quot;

Please help
 
What do yu mean by a cursor? Do you mean in a textfield/area? Could you please clarify?

Key capture is impossible, (I have on good authority)

-Ben &quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
to make it further clear

I would like to implement it through javascript in the TEXTAREA
 
Use onkeydown, onkeyup, or onkeypress and the unicode value of the key that triggered the event can be accessed via event.keyCode. I think the enter key is 0000. Go to to search key codes.

This works in IE, but I doubt Netscape uses this.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
and there's no way to find out the cursor position in a text area (previous thread on the same subject's conclusion !!)
 
you can capture the enter key in a text area, but I have'nt been able to in a text input field:

<script>
function handleKey(obj)
{
if(window.event.keyCode==13)
{
obj.value+=&quot;<li>&quot;
}
}
</script>

<body>
<textarea onkeypress=&quot;handleKey(this)&quot;></textarea>

</body> jared@aauser.com
 
if the purpose is to turn user input into list elements you could always do it after they've left the field
set onBlur to call a function which could replace any \n with \n<li>
you would have to check that you weren't doing a replacment that had already been done! ( eg. \n<li> to \n<li><li> )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top