textbox trouble

N

netnatter

I am trying to allow my users to paste text from a dropdown list into a
textbox at the current cursor position

I searched and found some code in a forum but it does not seem to work

As a half-way-house I tried a test page with a textbox and a paste icon to
click but still no go

It nees to worl on IE and firefox

Any ideas where I am going wrong?

My test code is...

<%@ Page Language="VB" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<title>Untitled Page</title>
<script type="text/javascript">
<!--
function insertAtCursor(elementRef, valueToInsert)
{
if ( document.selection )
{
// Internet Explorer...

elementRef.focus();
var selectionRange = document.selection.createRange();
selectionRange.text = valueToInsert;
}
else if ( (elementRef.selectionStart) || (elementRef.selectionStart ==
'0') )
{
// Mozilla/Netscape...

var startPos = elementRef.selectionStart;
var endPos = elementRef.selectionEnd;
elementRef.value = elementRef.value.substring(0, startPos) +
valueToInsert + elementRef.value.substring(endPos,
elementRef.value.length);
}
else
{
elementRef.value += valueToInsert;
}
}
// -->
</script>

</head>
<body>
<form id="form1" runat="server">

<asp:TextBox ID="TextBox1" runat="server" Height="345px"
TextMode="MultiLine"
Width="465px"></asp:TextBox>
<img src="http://www.e-ictsupport.org/paste.jpg"
onclick="javascript:insertAtCursor('Textbox1','hello');"/>

</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top