Reset Cursor after inserting bbcode

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Reset Cursor after inserting bbcode

Post by kendall »

I'm trying to build a form similar to this on that i am using to post this message .

I have the following script that inserts the bbcode when a user selects a text

Code: Select all

function storeCaret (textEl) {
       if (textEl.createTextRange) 
         textEl.caretPos = document.selection.createRange().duplicate();
     }

function insertTags(text,opentag,closetag){
		// get text 
		if(text.createTextRange)
			textSelection = document.selection.createRange().text; 
		// insert tags
		if(textSelection)
			document.selection.createRange().text = opentag+textSelection+closetag;
		eval(text).focus();
		theSelection = '';
		return;
		storeCaret(eval(text));
	 }
However i am not getting to reset the cursor at the end of the textarea.value when i

Code: Select all

onClick="insertTags(this.form.aTextArea,'їi]','ї/i]');"


I can't understand why it isnt working

Kendall
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first off, storeCaret will never be called.
second, I don't think you need to eval anything.. you're sending an object in 'text' .. not a string.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Ok....but no matter where it is i still dont get to reset the cursor to the textarea content Kendall
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Out of interest - which browser are you using?

Mac
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

is that code cross-browser compatible?
if you get this to work, I would be more than happy if you could post the code, I need something like this for my CMS :)
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

twigle,

Its not cross browser actually but im working on it. Im using it on IE 6

Kendall
Post Reply