Click to See Complete Forum and Search --> : phpbb style editor


bahith
10-03-2003, 09:40 AM
hi,
i have been looking for a phpbb style editor to use in my php scripts
for some time now with no luck.

i'm not familier with javascript, so i would really appreciate it if someone could help me,
and tell me how i can have a button and a textarea, when i highlight a word in this textarea
and press the button, two different tags appear before and after the highlited word,

thanks in advance.

pyro
10-03-2003, 10:48 AM
As far as I know, there is no DOM compliant way to get the selected text. This should work in IE, though:

<script type="text/javascript">
function addFormatting(tag) {
document.myform.mytext.focus();
document.selection.createRange().text = "<"+tag+">"+document.selection.createRange().text+"</"+tag+">";
}
</script>
</head>
<body>
<form name="myform">
<p><textarea name="mytext" rows="10" cols="50"></textarea><br>
<input type="button" value="<strong>" onclick="addFormatting('strong');">
<input type="button" value="<em>" onclick="addFormatting('em');">
<input type="button" value="<u>" onclick="addFormatting('u');"></p>
</form>

bahith
10-03-2003, 03:36 PM
thanks for youre reply pyro,
i still haven't tried the code,
but i'm beginning to think that there is a soloution for this problem.

thanks again.

pyro
10-03-2003, 03:42 PM
Sure thing -- just remember that that code isn't at all cross browser compatable.