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

Insert At Cursor

nathj
Expert 100+
P: 938
Good morning,

Well after the long Christmas break I'm finally back on-line, although my first post is to ask for help.

I am working on a simple admin panel for a site I have - it will enable other people to keep the main areas of the site up to date if I am not available. Part of this admin process needs an insert at cursor function so people can insert images at the right place.

The code I have (see below) works fine for FF but for IE nothing happens.

Expand|Select|Wrap|Line Numbers
  1. function insertAtCursor(myField, myValue) 
  2. {
  3.  
  4.     var loTextArea = document.getElementById(myField) ;
  5.  
  6.     if (document.selection) 
  7.     {
  8.         //IE support
  9.         myField.focus();
  10.         sel        = document.selection.createRange(); 
  11.         myValue    = myValue + sel.text;    
  12.     }
  13.     else if (loTextArea.selectionStart || loTextArea.selectionStart == '0')     
  14.     {                                                                            
  15.         //MOZILLA/NETSCAPE support     
  16.         var startPos        = loTextArea.selectionStart;
  17.         var endPos            = loTextArea.selectionEnd;
  18.         loTextArea.value    = loTextArea.value.substring(0, startPos) + myValue + loTextArea.value.substring(endPos, loTextArea.value.length);
  19.     }
  20.     else
  21.     {
  22.         loTextArea.value += loTextArea;
  23.     }
  24.  
  25. }
  26.  
I say nothing happens because that is exactly what happens - nothing. I am calling the function with the ID of a textarea and the string '[img]' which is translated later.

So in FF the insert happens where the cursor is but in IE nothing happens at all.

Any ideas on what is going wrong here?

Many thanks
nathj
Jan 19 '09 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
See if this thread helps.
Jan 19 '09 #2

nathj
Expert 100+
P: 938
That link turns up a 404, any ideas where the content is now?

Cheers
nathj
Jan 20 '09 #3

acoder
Expert Mod 15k+
P: 16,027
Sorry, the link was incorrect. I've fixed it now.
Jan 20 '09 #4

Post your reply

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