Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Text Cursor in a Text Box

Status
Not open for further replies.

fmh

Technical User
Jan 19, 2003
4
US
Hi all,
Does anyone have an idea how can we insert some text AT THE CURRENT LOCATION OF THE TEXT CURSOR in a text box (IE 5.x)? Any help is highly appreciable.
 
I'm not sure what you mean, if your looking for a way to have text pre-entered into a Text Box, you can use...

<INPUT TYPE=&quot;text&quot; NAME=&quot;textbox1&quot; VALUE=&quot;Put pre-entered text here.&quot;>

The value (same for most input forms) places that assigned value in the form. Jonathan Hannan
Computer Repair, Webdesign
HTML, CGI, PERL, JavaScript, XML
 
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<!-- <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../include/LPS.css&quot;> -->
<style type=&quot;text/css&quot;>
<!--
.textarea { font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal; line-height: normal; color: #000066; background-color: #CCCCCC; letter-spacing: normal; text-align: left; vertical-align: baseline; word-spacing: normal; white-space: normal; left: 10pt; top: 5px; clip: rect( ); background-image: url(Images/bgmeas3.gif)}
.template { font-family: Arial, Helvetica, sans-serif; font-size: 12pt; font-style: normal; line-height: normal; font-weight: bold; font-variant: small-caps; text-transform: none; color: #000000; background-color: #FFCCCC}
-->
</style>
<STYLE>
#contextMenu {
position: absolute;
visibility: hidden;
width: 120px;
background-color: lightgrey;
layer-background-color: lightgrey;
border: 2px outset white;
}

.A:Menu {
color: black;
text-decoration: none;
background-color: darkblue;
cursor: default;
width: 100%
}

.A:MenuOn {
color: white;
text-decoration: none;
background-color: darkblue;
cursor: default;
width: 100%
}
</STYLE>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var Xcoord, Ycoord;
var isNav, isIE;

var menu;
//-
//- Check for the key stroke event looking for the &quot;{&quot; key.
//-
function showMenu (evt) {

// alert(&quot;made it to showMenu&quot;);
if (document.all) {
//alert(&quot;in document.all&quot;);
//document.all.contextMenu.style.pixelLeft = event.clientX;
//document.all.contextMenu.style.pixelTop = event.clientY;
document.all.contextMenu.style.pixelLeft = Xcoord;
document.all.contextMenu.style.pixelTop = Ycoord;
document.all.contextMenu.style.visibility = 'visible';
return false;
}
else if (document.layers) {
if (evt.which == 3) {
alert(&quot;in evt.which 3&quot;);
// djm -- document.contextMenu.left = evt.x;
// djm -- document.contextMenu.top = evt.y;
document.contextMenu.left = Xcoord;
document.contextMenu.top = Ycoord
document.contextMenu.onmouseout =
function (evt) { this.visibility = 'hide'; };
document.contextMenu.visibility = 'show';
return false;
}
}
return true;
}
//-
//- Well, I guess this is fall through logic for now.
//-
if (document.all)
{
document.oncontextmenu =showMenu;
} // end of document.all

if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = showMenu;
}// end of document.layers

//-
//- Check for the key stroke event looking for the &quot;{&quot; key.
//-
function PasteIt(id)
{
//-
//- for through the loop
//-
for (var i = 0; i < document.anchors.length; i++) // was links
{
if (i == id)
{
document.letter_form.pasteText.value = document.anchors.name;
var Range1 = document.letter_form.pasteText.createTextRange();
} // end if the for nteger is equal to id number passed.
} // end for statement through anchors collection.
Range1.execCommand(&quot;Copy&quot;);
//-
//- set the range and paste the button contents at the offset
//- set by the user.
//-
//for (i=0;i< parent.frames.length;i++)
//{
//alert(&quot;text [&quot;+parent.frames.name+&quot;]&quot; );
//if (parent.frames.name == &quot;mainFrame&quot;)
//{
// Range = parent.frames.letter_form.txt_letter_text.createTextRange();
//}
//}

//window.clipboardData.setData(&quot;Text&quot;, pasteText);
//btnRange.execCommand(&quot;Copy&quot;);
Range = document.letter_form.mytextarea.createTextRange();
//Range.select();
offsetX = Xcoord;
offsetY = Ycoord;
Range.moveToPoint(offsetX,offsetY);
alert(&quot;Range.length [&quot;+Range.length+&quot;]&quot;);
for (var i=0; i > Range.length; i++)
{
alert(&quot;i [&quot;+i+&quot;]&quot;);
}
//Range.expand(&quot;word&quot;);
//Range.select();
//Range.collapse(false);
Range.execCommand(&quot;Paste&quot;);
document.onkeypress = null;
return false; // do not submit the form

}// end of function

//-
//- when the user sets the mousedown event in the textarea... grab the
//- X and Y coordinates.
//-
function setXY()
{
Xcoord = window.event.x;
Ycoord = window.event.y;
}


//-
//- Check for the key stroke event looking for the &quot;{&quot; key.
//-
function checkKey(evt)
{
if (isNav)
{
theBtnOrKey = evt.which;
} // end of if isNav

if (window.event.srcElement.type == &quot;textarea&quot;)
{
//alert(&quot;window.event.KeyCode &quot; + window.event.keyCode);
if (window.event.keyCode == 123) // check for &quot;{&quot; keystroke
{
//alert(&quot;window.event.KeyCode &quot; + window.event.keyCode);
if (document.all)
{
Xcoord = window.event.x;
Ycoord = window.event.y;
document.onkeypress = showMenu;
} // end of if document.all

if (document.layers)
{
//alert (&quot;made it 2&quot;);
document.captureEvents(event.KEYPRESS);
document.onkeypress = showMenu;
} // end of document.layers
} // end of window.event.keyCode
} // end of window.event.srcElement.type
} // end of function
</SCRIPT>
</head>

<body>
<form name=&quot;letter_form&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;pasteText&quot; value=&quot;&quot;>
<!-- ONMOUSEOUT=&quot;menu = this; this.tid = setTimeout ('menu.style.visibility = \'hidden\'', 20);&quot; onmouseover=&quot;clearTimeout(this.tid);&quot; -->
<textarea id=&quot;mytextarea&quot; class=&quot;textarea&quot; onmousedown=&quot;setXY();&quot; onkeypress=&quot;checkKey(event);&quot; cols=&quot;90&quot; rows=&quot;20&quot; wrap=&quot;hard&quot; ></textarea>

<DIV ID=&quot;contextMenu&quot;
ONMOUSEOUT=&quot;menu = this; this.tid = setTimeout
('menu.style.visibility = \'hidden\'', 20);&quot;
ONMOUSEOVER=&quot;clearTimeout(this.tid);&quot;
>
<A NAME=&quot;{ACCOUNT_NUMBER}&quot;; HREF=&quot;{ACCOUNT_NUMBER}&quot;; ID=0; CLASS=&quot;menu&quot;
ONMOUSEOVER=&quot;this.className = 'menuOn'&quot;
ONMOUSEOUT=&quot;this.className = 'menu';&quot;
ONCLICK=&quot;return PasteIt(0);&quot;
>
Account Number
</A>
<BR>
<A NAME=&quot;{ACCOUNT_DATE}&quot;; HREF=&quot;{ACCOUNT_DATE}&quot;; ID=1; CLASS=&quot;menu&quot;
ONMOUSEOVER=&quot;this.className = 'menuOn'&quot;
ONMOUSEOUT=&quot;this.className = 'menu';&quot;
ONCLICK=&quot;return PasteIt(1);&quot;
>
Account Date
</A>
</DIV>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top