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!

Insert text into textarea at cursor position 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I have a form with a textarea and a droplist of phrases. I'd like to get it so that if someone chooses a phrase from the droplist it goes into the textarea at wherever the cursor was before the user clicked on the droplist. Is this possible?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Hi

In Gecko, Presto, WebKit and KHTML you can use the [tt]textarea[/tt]'s [tt]selectionStart[/tt] / [tt]selectionEnd[/tt] property like this :
Code:
[b]<textarea[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"ta"[/i][/green][b]>[/b][b]</textarea>[/b]

[b]<select[/b] [maroon]onchange[/maroon][teal]=[/teal][green][i]"with(document.getElementById('ta'))value=value.substr(0,selectionStart)+this.value+value.substr(selectionStart);this.selectedIndex=0"[/i][/green][b]>[/b]
[b]<option>[/b]- insert -[b]</option>[/b]
[b]<option>[/b]Hello World[b]</option>[/b]
[b]<option>[/b]Tek-Tips Rocks[b]</option>[/b]
[b]</form>[/b]
As far as I know, this will not work in Trident.

Feherke.
 
Thanks.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top