By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,962 Members | 578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,962 IT Pros & Developers. It's quick & easy.

manipulation of textarea selection

P: 4
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:
// JS:
function getsel(){
var sel = document.getElementById('editbox').selection;
// HTML:
<textarea .... id="editbox"></textarea>
<input type="button" value="click" onclick="getsel();">

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


Gives 'undefined', and
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...

Sep 29 '07 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027

P: 4
Thanks, I'll read through that.

Oct 1 '07 #3

P: 4
just for reference, I found an excellent script for the job here:
Oct 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.