I'm currently working on a PHP CMS for my school that uses simple forms to update the pages and database. To get it out in use, it will have to be usable by people who don't know that [ b ] is bold, and all the rest of it. I have noticed that vBulletin has the best formatting buttons (and no, I'm not talking about the WYSIWYG editor, I know that's way beyond me) so I was thinking of something similar (if I get bold, italic and underlined working, I'm happy). Just for testin, and based on a few things I read about selection, I have the following:
[HTML]
// JS:
function getsel(){
var sel = document.getElementById('editbox').selection;
alert(sel.type);
}
// HTML:
<textarea .... id="editbox"></textarea>
<input type="button" value="click" onclick="getsel();">
[/HTML]
I know that won't do much, bit it should at least say "Text" or something (presuming that I have written and selected text in the textarea), but it doesn't. In the error console (both in Opera and FF), it says something along the lines of "sel has no properties". replacing
[HTML]
alert(sel.type);
with
alert(sel);
[/HTML]
Gives 'undefined', and
[HTML]alert(sel.value);[/HTML]
works, giving whatever happens to be written in it.
So something's wrong...
If anyone has a good howto, or can be bothered to explain this whole selection business to me, it would be much appreciated. Basically what I want to do is take the selection (or, if there is none, the location of the cursor) and stick stuff around it... As you can see, JS isn't my great strength...
Thanks,
-K