Drag & drop issue

M

Martin Honnen

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>
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top