By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

Drag & drop issue

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a


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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.