HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 16th, 2004, 08:44 AM
starbar starbar is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 starbar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Inserting at caret position

I have a JavaScript function that is supposed to insert 2 html <br> tags into a textarea (txtUnformattedContent) but instead it is printing the <br><br> at the last point I click anywhere in the browser window. If the last place I click is within txtUnformattedContent the <br><br> appears at the very top of the screen. My code is:


<textarea name="txtUnformattedContent" id="txtUnformattedContent" rows="8" cols="24" onChange="setFormattedContent(this);" onKeyUp="countWords(this);storeCaret(this);" onSelect="storeCaret(this);" onBlur="storeCaret(this);"></textarea>



<a href="#" ONCLICK="insertAtCaret(document.getElementById('txtUnformat tedContent'),'<br><br>');">
<td bgcolor="#FFFFFF" width="33%" align="center" title="Line Break">
Line Break
</td>
</a>



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

function insertAtCaret (textEl, text)
{
if (textEl.createTextRange && textEl.caretPos)
{
var caretPos = textEl.caretPos;
caretPos.text =
caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
text + ' ' : text;
}
else
{
textEl.value = text;
}
}



Can anyone figure out what the problem is?

Thanks!

Reply With Quote
  #2  
Old March 19th, 2004, 02:41 AM
kidpaddle kidpaddle is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 kidpaddle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
When you click on an other element you loose the selection object unless you set the UNSELECTABLE attribute for all the others elements on the page.

Code:
 
function fnInit(){
	<!-- Ensure the display interface is not selectable, by making all	 -->
	<!-- elements UNSELECTABLE											 -->
	for (i=0; i<document.all.length; i++)
			document.all(i).unselectable = "on";
	<!-- Prepare the editable regions									  -->
	oDiv.unselectable = "off";
	oTextarea.unselectable = "off";
}

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Inserting at caret position


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT