473,490 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Drag & drop issue

Hi everyone,

Is is possible and how would I implemente dragging and dropping a value in a textbox so that it would clear the existing value in
the textbox, if it has one already?

TIA

Joseph

philippeoget at hotmail dot com
http://www.geocities.com/philippeoget/a2z/
Jul 23 '05 #1
2 1735


Joseph wrote:

Is is possible and how would I implemente dragging and dropping a value in a textbox so that it would clear the existing value in
the textbox, if it has one already?


IE (5 and later) on Win has support for drag/drop handlers, here is a
simple example tested with IE 6 where any text dropped on the text input
replaces the existing value of the control:

<html lang="en">
<head>
<title>custom drop on text control</title>
<script type="text/javascript">
function dropHandler (evt) {
evt = evt || window.event;
if (evt.srcElement && evt.srcElement.type && evt.dataTransfer &&
(evt.srcElement.type == 'text' || evt.srcElement.type == 'textarea'))
{
evt.srcElement.value = evt.dataTransfer.getData('Text');
return false;
}
}

function setDropHandler (elementId, dropHandler) {
var element;
if (document.getElementById && (element =
document.getElementById(elementId))) {
element.ondrop = dropHandler;
}
}
</script>
</head>
<body>
<h1>custom drop</h1>

<p>Select text here and drag and drop on text control.</p>

<div>
<input type="text" id="input1" value="Kibology">
</div>

<script type="text/javascript">
setDropHandler('input1', dropHandler);
</script>

</body>
</html>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin that is superb! Thank you very much.
Joseph

philippeoget at hotmail dot com
http://www.geocities.com/philippeoget/a2z/
"Martin Honnen" <ma*******@yahoo.de> wrote in message news:42***********************@newsread4.arcor-online.net...


Joseph wrote:

Is is possible and how would I implemente dragging and dropping a value in a textbox so that it would clear the existing value in
the textbox, if it has one already?


IE (5 and later) on Win has support for drag/drop handlers, here is a simple example tested with IE 6 where any text dropped on
the text input replaces the existing value of the control:

<html lang="en">
<head>
<title>custom drop on text control</title>
<script type="text/javascript">
function dropHandler (evt) {
evt = evt || window.event;
if (evt.srcElement && evt.srcElement.type && evt.dataTransfer &&
(evt.srcElement.type == 'text' || evt.srcElement.type == 'textarea'))
{
evt.srcElement.value = evt.dataTransfer.getData('Text');
return false;
}
}

function setDropHandler (elementId, dropHandler) {
var element;
if (document.getElementById && (element = document.getElementById(elementId))) {
element.ondrop = dropHandler;
}
}
</script>
</head>
<body>
<h1>custom drop</h1>

<p>Select text here and drag and drop on text control.</p>

<div>
<input type="text" id="input1" value="Kibology">
</div>

<script type="text/javascript">
setDropHandler('input1', dropHandler);
</script>

</body>
</html>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #3

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

Similar topics

3
2191
by: Fred R | last post by:
I'm designing an app in Access 97 that will facilitate the uploading of records and images to a website. The user selects the image thumbnails from the file system and drags them into the app....
2
9171
by: Grey | last post by:
I need to design a workflow application with C#. I want to design an UI with some workflow components which they can be drag & drop anywhere in order to design the workflow for the application...
2
1349
by: memHog | last post by:
I am trying to create a windows application that will perform drag and drop between a usercontrol on a toolbar and a "user document". As the user control is being dragged accross the user...
6
3525
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
1
2293
by: Terry Olsen | last post by:
My first time using TreeViews. I have TreeView1 set up to display my directory structure just like Windows Explorer. I can drag & drop files and folders over to TreeView2. I can re-arrange the...
3
10560
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
17
31536
by: Romulo NF | last post by:
I´ve seen some people around the web wondering about a code to reorder table columns using the mouse (drag and drop). Since i had already made one script to reorder table lines (TR´s) i decided to...
5
13723
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
2
2628
by: deccio | last post by:
I have create an activex Control with Visual studio 2005 and framework 2.0 in c# to add drag & drop functionality to upload multi file. When I use it in a windows form it work fine. Infact if I...
0
7112
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
7146
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
7183
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
7356
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
5448
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
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.