473,388 Members | 981 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,388 software developers and data experts.

insert text in textarea on right click in java script

Max
i want to insert a predefined string in a textarea when i right click
on the mouse. i need to do it in internet explorer and mozilla.
Jul 20 '05 #1
6 11564
"Max" <ma********@optonline.net> wrote in message
news:3a*************************@posting.google.co m...
i want to insert a predefined string in a textarea when i right click
on the mouse. i need to do it in internet explorer and mozilla.


Try:

<script type="text/javascript">
var myText = "Predefined text";
function insertText(obj,e){
var button = e.button || e.which;
if (button == 2){
obj.value=myText; // or obj.value += myText;
}
}
</script>
<textarea onmousedown="insertText(this,event);"></textarea>

Vjekoslav
Jul 20 '05 #2
thanks for the reply, but it didn't work in either IE or mozilla.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
"max zen" <ma********@optonline.net> wrote in message
news:3f*********************@news.frii.net...
thanks for the reply, but it didn't work in either IE or mozilla.


It works when you right click in textarea.
Jul 20 '05 #4
Max
yes, you're right it does work. i don't know what happened the first
time. the exact function that i am looking for is to insert a "*"
whenever i click in the textarea that already contains text. the
posted function works but only adds the predefined text. i want to
insert into the cursor location the pre defined text. i tried += but
it only appends the predefined text. I will need to insert the
predefined text multiple number of times at different cursor
locations.
Jul 20 '05 #5
"Max" <ma********@optonline.net> wrote in message
news:3a**************************@posting.google.c om...
yes, you're right it does work. i don't know what happened the first
time. the exact function that i am looking for is to insert a "*"
whenever i click in the textarea that already contains text. the
posted function works but only adds the predefined text. i want to
insert into the cursor location the pre defined text. i tried += but
it only appends the predefined text. I will need to insert the
predefined text multiple number of times at different cursor
locations.


OK, this works on IE6 (not tested on other browsers).

<script type="text/javascript">
// I found this on
http://www.faqts.com/knowledge_base/...d/1052/fid/130
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;
}
</script>

<script type="text/javascript">
var myText = "Predefined text";
function insertText(obj,e){
var button = e.button || e.which;
if (button == 2){
insertAtCaret(obj,myText)
}
}
</script>
<textarea onmousedown="storeCaret(this);insertText(this,even t);"></textarea>

HTH,

Vjekoslav
Jul 20 '05 #6
The code does work, but incorrectly. It inserts the predefined text into
the previous cursor position. So there is a single click delay. The
predefined text does not appear immediately. On the subsequent click,
the predefined text is inserted into the previous cursor position. Also
we have the context menu pop up also. We lay this away for a while and
have been working on it without the desired solution. I would appreciate
your attention.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Doug van Vianen | last post by:
Hi, I am working on an Applet which provides some mouse practice for new computer users in our local seniors' computer club. The applet contains several cards, in a card layout, which are...
12
by: who be dat? | last post by:
I'm trying to make a webpage do the following: I want a user to be able to click on a given image (there will be more than one image). Upon clicking a given image, characters specific to that...
7
by: Paul Gorodyansky | last post by:
Hi, Say I have a text in my TEXTAREA box - 01234567890 I want - using script - insert say "abc" in the middle. Works almost OK in Internet Explorer (with one problem) based on their example...
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
15
by: globalrev | last post by:
i have a translator-program for the robbers language. i want the user to input into the topwindow and then display the encryption or decryption in the bottom window. i am currently trying to...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: brianrpsgt1 | last post by:
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.