PDA

View Full Version : event.dataTransfer.setData


joergen
18.05.2001, 07:37
hi hoping someone can help me with this...

the dataTransfer.setData only seem to allow one value being passed, is this so? haven't been able to find any information concerning this. i mean, what's the purpose of being able to set two properties (URL and Text) if you can only set one at a time. one can just as well grab the url as text and pass it along that way (which actually is what happens - when URL is set, the Text property has the same value).

now what i'd like to do is transfer some image information - URL and text (actually a db guid) - to two seperate inputfields.

my code looks something like this:

<script>

function fnSetInfo()
{ // Sets data format in first parameter
window.event.dataTransfer.setData("URL", oSource.src); // and provides text to drop in second.
//window.event.dataTransfer.setData("Text", "OK"); <-- not working
window.event.dataTransfer.effectAllowed = "copy"; // Copies text.
}

function fnCancelDefault()
{ // Cancel default action in ondragenter
event.returnValue = false; // and ondragover so that copy cursor will
window.event.dataTransfer.dropEffect = "copy"; // display until selection is dropped.
}

function FinishDrag()
/* The parameter passed to getData tells the target
object what data format to expect. */
{
sImageURL = event.dataTransfer.getData("URL");
//sImageText = event.dataTransfer.getDate("Text"); <-- not working

bTarget.src = sImageURL;
//oTarget.value = sImageText; <-- not working

}
</script>

<body>
../images/house.jpg
<input type=image src="/jblokal/images/wbc-bild.gif" border=0 id=bTarget value="test" ondragenter="fnCancelDefault()" ondragover="fnCancelDefault()" ondrop="FinishDrag()">
</body>

am i doing something wrong or is this just the regular behaviour?

thanks for you help!
Joergen

joergen
18.05.2001, 07:40
sorry forgot this line:
<input ID="oTarget" type="hidden" VALUE="some default value" ondragenter="fnCancelDefault()" ondrop="fnGetInfo()" ondragover="fnCancelDefault()">

bratta
18.05.2001, 07:52
I haven't worked a lot with these things since they are IE only, but I'll give it a go.

As far as I know URL and TEXT is not 2 properties in this case. It's just the way to format the data. And as you said the setData only takes 2 parameters, the DATAFORMAT (Url or Text) and the actual data.

This looks like a microsoft example so I assume you've seen the microsoft info on this, but I'll post the urls anyway:

setData: http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/setData.asp

getData:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getData.asp



-Thomas Brattli-
http://www.bratta.com/
http://www.dhtmlcentral.com/

joergen
18.05.2001, 08:10
guessing you're right thomas. that fact that it's ie only is ok, it's being used for a cms system in a homogenous intranet.
i'll have to figure someway out to store all my information as a textstring and split it up at dragend. man, they should add an array format :)

thanks anyway...

Joergen:)

bratta
18.05.2001, 08:19
I was thinking the same thing. Storing it as a string and splitting it up I mean. Shouldn't be a problem.

-Thomas Brattli-
http://www.bratta.com/
http://www.dhtmlcentral.com/