473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

cursor postion in textarea

12
i have a list box and one textarea i am trying to pull the tags from list box (on click on the tags of my list box or onclick of a button )into my textarea whereever the cursor is focused but without clicking my textarea its adding only in the first.if i click in the textarea it adding properly.

function setCursorPos() {
globalCursorPos = getCursorPos(FileColumnData.messageText);


}


function getCursorPos(textElement) {

var sOldText = textElement.value;

var objRange = document.selection.createRange();
var sOldRange = objRange.text;

var sWeirdString = '#%~';

objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));

var sNewText = textElement.value;

objRange.text = sOldRange;

for (i=1; i <= sNewText.length; i++)
{
var sTemp = sNewText.substring(i, i + sWeirdString.length);
if (sTemp == sWeirdString) {
var cursorPos = (i - sOldRange.length);
return cursorPos;
}
}

return 0;
}


function insertdata() //for button
{
var msg = document.FileColumnData.columnData.value;
var firstPart = FileColumnData.messageText.value.substring(0,globa lCursorPos);
var secondPart = FileColumnData.messageText.value.substring(globalC ursorPos,FileColumnData.messageText.value.length);
document.FileColumnData.messageText.value = firstPart + msg + secondPart ;
document.FileColumnData.messageText.focus();

}

function insertString(stringToInsert)//for list box
{
var firstPart = FileColumnData.messageText.value.substring(0, globalCursorPos);
var secondPart = FileColumnData.messageText.value.substring(globalC ursorPos,FileColumnData.messageText.value.length);
document.FileColumnData.messageText.value = firstPart + stringToInsert + secondPart;
document.FileColumnData.messageText.focus();
}
Jun 21 '07 #1
1 1295
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Why not give focus to the textarea first?
Jun 21 '07 #2

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

Similar topics

3
by: Krzysztof Kujawski | last post by:
Hi Is there posibility to (and how to do this): a) add a string in the current cursor position? b) add string before and after selection in textarea e.g. selection c) if I put with...
3
by: PeP | last post by:
Good morning, I have a form containing a text-area, I'd like to know if it exists a function that, when I activate an event, returns the position of the cursor in the text-area. For example, I...
1
by: Merlin | last post by:
Hi there, I would like to set the cursor upon loading a page on a text field which has already been populated. The problem with this code: <script language="JavaScript1.1"...
12
by: andreas | last post by:
Hi, A button in a child form creates another form with a textbox showing with show. I set the taborder on first on this textbox in the design and set even the focus by loading but i see no...
4
by: Christopher Finke | last post by:
I am writing a Web-based text editor that will be used mainly for editing code. To facilitate this task, whenever the Enter button is pressed within the textarea, the event is caught and the next...
2
by: Michael | last post by:
Question 1 ---------------- I am writing an advanced BBCode system for my forums and I would like to be able to find where the cursor was positioned last in the text so I could insert the BBCode...
1
by: arash | last post by:
Hi! I am trying to write some ajax based IDE. I just cant get a div to open where the cursor in the textarea is blinking (in order to suggest possibilities..) Is there a way to get the exact...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.