This is a discussion on "selections within textareas" within the JavaScript Forum section. This forum, and the thread "selections within textareas are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
selections within textareas
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
selections within textareas
i really didn't know where to put this!
its done on a lot of sites (including this one!), but how is it done? how can you detect what is highlighted in a textarea, and then add text around it? for example, they can highlight a word and click bold and it adds bold tags around it...? how?! thanks bacardi |
|
|
|
#2
|
||||
|
||||
|
using the textRange object....
haven't done it in a while, lemme find it for you...
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#3
|
||||
|
||||
|
this should do:
http://msdn.microsoft.com/library/de.../textrange.asp http://msdn.microsoft.com/library/de..._textrange.asp
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#4
|
||||
|
||||
|
ok thanks spinal but i never understand the msdn language - its too technical for me! Do you think you could explain it to me in more simple terms? much appreciated if you can...
|
|
#5
|
|||
|
|||
|
This is my code to make the highlited text to be a url link..
Just put this on the <head> tag... and call them using an gif or a text.
I'll post to you later, ok
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
|
#6
|
||||
|
||||
|
thanks monie... it would be good if you could post the full code
|
|
#7
|
||||
|
||||
|
I'm not good at these things but i'll explain monie's code...
THE IDEA: the textRange object lets you rerieve and change text within an element. USES: "document.selection" points to the current selection on the document (duh!) I made a small example so you can try it out yourself. save this onto a htm file and run it:
2 . click the "Make Selection Bold" button 3 . that will trigger a function wi=hich will: 3 a) find the selection in the body of the document 3 b) retrieve the selected text 3 c) replace it by the same selected text sorrounded by the "[b]" tag
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#8
|
|||
|
|||
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
|
#9
|
||||
|
||||
|
thanks guys i've worked it out and written one of my own...
|
|
#10
|
||||
|
||||
|
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />Originally posted by benbacardihow did you make one that updates it automatically like that<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">
what do you mean? basics of editors: (as far as I know) - manipulate the code - show result so user "thinks" he's changing the text to bold while in fact he's placing "[b]"tags around it simple implementation: - use a textarea for the code - create buttons that will insert whatever formatting to the code (just like the editor in this forum) - use jscript to write the content of the textarea onto the document so you can see the HTML result. for this, use textRange.pasteHTML([textarea contents]);
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#11
|
||||
|
||||
|
i mean how do you make something like this http://www.dotmagic.co.uk/richeditor
|
|
#12
|
||||
|
||||
|
Ben.... thats mine.. lol
That one sadly only works in internet explorer. If it were for an intra-net where all users had IE, then it would be perfect. I wrote that one about a year ago and never used it.... it's still unfinished!
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#13
|
||||
|
||||
|
I would not advice you designing your own HTML editor for the following reasons:
1. there's free stuff out there. many very talented programmers (God bless the bastards) spend months or even years developing the most sweet pieces of coding you ever seen and let you use at at will. I gave up my own editor when I found htmlArea (http://www.interactivetools.com/products/htmlarea/) 2. having made the point above, you'll be wasiting your time trying to design something that will match the quality of the above, so unless you're simply trying to learn a few techniques, don't go all the way. by all means try and re-create the software in your own way, practice and learn from the code, but anyone is better off taking advantage of the free software available. 3. I forgot wat my third point was... as posted here: http://www.webforumz.com/topic.asp?TOPIC_ID=1946
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
|
|
#14
|
|||
|
|||
|
ive had problems with HTMLArea, the best ive found is: http://richtext.sourceforge.net/
|
|
#15
|
||||
|
||||
|
What if you have 2 textareas, how can you determin in which of them the selection has been made?
|
|
#16
|
||||
|
||||
|
I dont quite understand what you mean. Each textarea would have an ID. You just reference each textbox by it's id and see which has the selection.
__________________
Click the 'Thanks!' button if this post has helped you Rob - Webforumz Founder
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
#17
|
||||
|
||||
|
and how do you do that?
|
![]() |
| Tags |
| selections, within, textareas |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Navigation from 2 pulldown selections? | svoltmer | JavaScript Forum | 2 | Apr 28th, 2008 12:28 |
| Highlighting text selections | mikemike2004 | JavaScript Forum | 6 | Mar 15th, 2008 21:24 |
| [SOLVED] color-box selections | pesho318i | JavaScript Forum | 6 | Dec 22nd, 2007 20:57 |
| PHP and textareas | ktsirig | PHP Forum | 3 | Sep 25th, 2005 22:41 |