I'm currently enhancing a Wiki script (Phiki Wiki from
http://ontosys.com/phiki/PhikiWiki ) and I want to add a feature where by
users can highlight some text in a text area on the "Edit Page" page and click
a button to add Wiki bold tags (or italic tags or whatever) around the
selected text. I know how to grab the currently selected text using DHTML:

http://www.xs4all.nl/~ppk/js/selected.html

My problem is then adding content (in this case Wiki tags) to either side of
the selected text. I've thought about doing it by running a simple replace
operation on the text in the textarea replacing "selectedtext" with
"*selectedtext*" - however this is not ideal as it will not work if the
selected text occurs more than once in the textarea (with the sentence "the
cat sat on the mat" for example, selecting the word "the" and hitting the
button would either add tags to every instance of "the" in the sentence or
only add tags to the first occurence of the word).

Is it possible to do what I am trying to do with Javascript? Ideally I would
like a solution for both Mozilla and IE, but I don't mind if it just works on
Mozilla.

Cheers,

Simon Willison


____________________________________________
 Buy sell and Swap stuff with people at your uni
 The dotuni Xchange - www.dotuni.com






