473,406 Members | 2,956 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,406 software developers and data experts.

textbox trouble

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','hel lo');"/>

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

Aug 22 '08 #1
1 1056
You are passing a string while your script expect an object. Make sure to
test each assumption you are doing to debug such as thing (for example you
also have a case difference so if you use getElementById make sure it
returns something at least when debugging etc...)

Step by step debuiign could also help as well as describe what is the
behavior you see... (and enabbling javascript error report in your browser
if not already done).

--
Patrice
"netnatter" <ne*******@ntlworld.coma écrit dans le message de groupe de
discussion : 1Y*****************@newsfe13.ams2...
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','hel lo');"/>

</form>
</body>
</html>
Aug 22 '08 #2

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

Similar topics

6
by: Karen | last post by:
I'm having trouble getting input from a textbox in Visual Basic 6.0 Private Sub cmdGetNumber_Click() txtInput.Text = Str(Int(1000 * Rnd)) End Sub The error message states: "Method or data...
1
by: crowl | last post by:
Hi all, I start developing for pocket pc with C# under VS.NET 2003. I run into trouble with the textbox settings. On the form I have placed a textbox. I noticed that in the textbox properties...
3
by: Sandy | last post by:
Hello - I have a page that runs a stored procedure checking for the existence of a name in a database. If it exists, lblMessage returns text indicating same. When a user goes back and clears...
7
by: Sandy | last post by:
Hello - I have a form that when submitted checks the database and if the username is already taken, a label shows indicating same. I need to make that label NOT visible after the user clicks...
0
by: jason | last post by:
Hello everyone. I am trying to write some custom command events into a DataGrid. The command that is currently giving me trouble is an "Add" custom command in the footer of a template column. ...
6
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of the fields to a textbox. After setting up the...
3
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new...
3
by: luanhoxung | last post by:
Hi all !! i have met trouble with referring textbox of subform in VBA i know i can do as: forms!mainform.subform.textbox but i want do it in shorter path. any suggestion about using variable ?...
0
by: CaJack | last post by:
Hi, I’m having trouble with my code and I’m starting to get lost. The Program takes the country that’s been typed in to the textbox and when the query button is clicked the program queries an access...
1
by: Jeff | last post by:
hi asp.net 2.0 Below is some markup I have trouble with. The problem is that the Textbox doesn't fill the entire DataCell. I've set width of TextBox to 100%.... The point is that I want the *...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.