Connecting Tech Pros Worldwide Forums | Help | Site Map

Drag & drop issue

Joseph
Guest
 
Posts: n/a
#1: Jul 23 '05
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/



Martin Honnen
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Drag & drop issue




Joseph wrote:

[color=blue]
> 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?[/color]

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/
Joseph
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Drag & drop issue


Martin that is superb! Thank you very much.


Joseph

philippeoget at hotmail dot com
http://www.geocities.com/philippeoget/a2z/
"Martin Honnen" <mahotrash@yahoo.de> wrote in message news:42497609$0$27191$9b4e6d93@newsread4.arcor-online.net...[color=blue]
>
>
> Joseph wrote:
>
>[color=green]
>> 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?[/color]
>
> 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/[/color]


Closed Thread