/    Sign up×
Community /Pin to ProfileBookmark

Drag and drop

Hi,

I have found this script that drags some text into an input field

[code=html]

<html>
<head>
<title>System Drag And Drop Example</title>
<script type=”text/javascript”>

function handleMouseMove(oEvent) {
if (oEvent.button == 1) {
oEvent.srcElement.dragDrop();
}
}

function handleDragDropEvent(oEvent) {

oEvent.dataTransfer.setData(“text”, “Paul”);
}
</script>
</head>
<body>
<p>Try dragging the red square into the textbox.</p>
<p><div style=”background-color: red; height: 100px; width: 100px”
onmousemove=”handleMouseMove(event)”
ondragstart=”handleDragDropEvent(event)”>Paul</div> </p>

<p><input type=”text” value=”” /></p>
</body>
</html>

[/code]

what I want is a list of text and the user chooses what to drag into the text box.
I have tried this code below

[code=html]

<html>
<head>
<title>System Drag And Drop Example</title>
<script type=”text/javascript”>

function handleMouseMove(oEvent) {
if (oEvent.button == 1) {
oEvent.srcElement.dragDrop();
}
}

function handleDragDropEvent(oEvent, name) {

oEvent.dataTransfer.setData(“text”, name);
}
</script>
</head>
<body>
<p>Try dragging the red square into the textbox.</p>
<p><div style=”background-color: red; height: 100px; width: 100px”
onmousemove=”handleMouseMove(event)”
ondragstart=”handleDragDropEvent(event, “Paul”)”>Paul</div> </p>

<p><div style=”background-color: red; height: 100px; width: 100px”
onmousemove=”handleMouseMove(event)”
ondragstart=”handleDragDropEvent(event, “Ron”)”>Ron</div> </p>

<p><input type=”text” value=”” /></p>
</body>
</html>

[/code]

The changes are the names that are being passes

Any ideas?

thanks in advance

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@sovikFeb 05.2007 — <i>
</i>&lt;html&gt; &lt;head&gt; &lt;title&gt;System Drag And Drop Example&lt;/title&gt; <br/>
&lt;script type="text/javascript"&gt; <br/>
function handleMouseMove(oEvent) {
if (oEvent.button == 1) {
oEvent.srcElement.dragDrop();
} }
function handleDragDropEvent(oEvent,nm) {
oEvent.dataTransfer.setData("text",""+nm+"");
}
&lt;/script&gt; <br/>
&lt;/head&gt; &lt;body&gt; &lt;p&gt;Try dragging the red square into the textbox.&lt;/p&gt; &lt;p&gt;
&lt;div style="background-color: red; height: 100px; width: 100px" onmousemove="handleMouseMove(event)" ondragstart="handleDragDropEvent(event,['Paul'])"&gt;Paul&lt;/div&gt;
&lt;div style="background-color: red; height: 100px; width: 100px" onmousemove="handleMouseMove(event)" ondragstart="handleDragDropEvent(event,['aaa'])"&gt;aaa&lt;/div&gt;
&lt;div style="background-color: red; height: 100px; width: 100px" onmousemove="handleMouseMove(event)" ondragstart="handleDragDropEvent(event,['ccc'])"&gt;ccc&lt;/div&gt;
&lt;/p&gt; &lt;p&gt;&lt;input type="text" value="" /&gt;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;



hopefully u can see the difference.
Copy linkTweet thisAlerts:
@vagasv1authorFeb 06.2007 — Fantastic Works like a dream
×

Success!

Help @vagasv1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...