abubadr
Anime Merchandise Pro
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
How to Transfer Dragged Element to HTML List in JavaScript
Introduction
In this tutorial we will create a How to Transfer Dragged Element to HTML List in JavaScript. This tutorial purpose is to teach you on how transfer the dragged element into html list. This will tackle all the important functionality that will display the html list. I will provide a sample program to show the actual coding of this tutorial.
This tutorial is simple and easy to understand just follow the instruction I provided and you can do it without a problem. This program can be use to any system or application if you want apply some drag and drop feature. I will give my best to provide you the easiest way of creating this program Transfer Dragged Element into HTML List. So let's do the coding.
Before we get started:
Here is the link for the template that i used for the layout design https://getbootstrap.com/.
Creating The Interface
This is where we will create a simple interface for our application. This code will only display the html form inputs and HTML list. To create this simply copy and write it into your text editor, then save it as index.html.
Creating JavaScript Function
This is where the main function of the application is. This code will transfer the dragged element into list when your submit the form. To do this just copy and write these block of codes inside the text editor and save it as script.js.
This code above uses only one method to transfer the element into html list called transfer(). This function will transfer the dragged element into html list after you submit the form inputs. To transfer a dragged element we just simply get the dragged data via the drag event then put it into the html form in order to submit the inputs.
Output:
The How to Transfer Dragged Element to HTML List in JavaScript source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Transfer Dragged Element to HTML List in JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for JavaScript Language
JavaScript Tutorials
Download
Introduction
In this tutorial we will create a How to Transfer Dragged Element to HTML List in JavaScript. This tutorial purpose is to teach you on how transfer the dragged element into html list. This will tackle all the important functionality that will display the html list. I will provide a sample program to show the actual coding of this tutorial.
This tutorial is simple and easy to understand just follow the instruction I provided and you can do it without a problem. This program can be use to any system or application if you want apply some drag and drop feature. I will give my best to provide you the easiest way of creating this program Transfer Dragged Element into HTML List. So let's do the coding.
Before we get started:
Here is the link for the template that i used for the layout design https://getbootstrap.com/.
Creating The Interface
This is where we will create a simple interface for our application. This code will only display the html form inputs and HTML list. To create this simply copy and write it into your text editor, then save it as index.html.
- <!DOCTYPE html>
- <html
lang
=
"en"
>
- <head
>
- <meta
charset
=
"UTf-8"
name
=
"viewport"
content
=
"width=device-width, initial-scale=1"
/
>
- <link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"css/bootstrap.css"
/
>
- </
head
>
- <body
>
- <nav
class
=
"navabr navbar-default"
>
- <div
class
=
"container-fluid"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav
>
- <br
/
>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
How to Transfer Dragged Element to HTML List</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-6"
>
- <div
class
=
"form-group"
>
- <input
class
=
"form-control"
type
=
"text"
id
=
"data"
ondrop
=
"drop(event)"
ondragover
=
"dragOver(event)"
readonly
=
"readonly"
/
>
- </
div
>
- <center><button
class
=
"btn btn-primary"
onclick
=
"transfer();"
><span
class
=
"glyphicon glyphicon-save"
></
span
>
Transfer</
button
>
<button
class
=
"btn btn-success"
onclick
=
"clearAll();"
><span
class
=
"glyphicon glyphicon-refresh"
></
span
>
Clear All</
button
></
center>
- <br
/
>
- <h3
>
=== MY LIST ===</
h3
>
- <div
id
=
"result"
></
div
>
- </
div
>
- <div
class
=
"col-md-6"
>
- <div
class
=
"alert alert-info"
>
Movie List</
div
>
- <h4
id
=
"Little Mermaid"
draggable
=
"true"
ondragstart
=
"drag(event)"
>
Little Mermaid</
h4
>
- <h4
id
=
"Spiderman Into Multiverse"
draggable
=
"true"
ondragstart
=
"drag(event)"
>
Spiderman Into Multiverse</
h4
>
- <h4
id
=
"Avatar 2"
draggable
=
"true"
ondragstart
=
"drag(event)"
>
Avatar 2</
h4
>
- <h4
id
=
"Guardian of the Galaxy"
draggable
=
"true"
ondragstart
=
"drag(event)"
>
Guardian of the Galaxy</
h4
>
- <h4
id
=
"Evil Dead"
draggable
=
"true"
ondragstart
=
"drag(event)"
>
Evil Dead</
h4
>
- </
div
>
- </
div
>
- <script
src
=
"script.js"
></
script
>
- </
body
>
- </
html
>
Creating JavaScript Function
This is where the main function of the application is. This code will transfer the dragged element into list when your submit the form. To do this just copy and write these block of codes inside the text editor and save it as script.js.
- function
dragOver(
e)
{
- e.preventDefault
(
)
;
- }
- function
drop(
e)
{
- e.preventDefault
(
)
;
- let data =
e.dataTransfer
.getData
(
"data"
)
;
- document.getElementById
(
'data'
)
.value
=
data;
- }
- function
drag(
e)
{
- e.dataTransfer
.setData
(
"data"
,
e.target
.id
)
;
- }
- function
transfer(
)
{
- let data =
document.getElementById
(
'data'
)
.value
;
- if
(
data !=
""
)
{
- document.getElementById
(
'result'
)
.innerHTML
+=
data+
"<br />"
;
- }
- }
- function
clearAll(
)
{
- document.getElementById
(
'result'
)
.innerHTML
=
""
;
- document.getElementById
(
'data'
)
.value
=
""
;
- }
This code above uses only one method to transfer the element into html list called transfer(). This function will transfer the dragged element into html list after you submit the form inputs. To transfer a dragged element we just simply get the dragged data via the drag event then put it into the html form in order to submit the inputs.
Output:

The How to Transfer Dragged Element to HTML List in JavaScript source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Transfer Dragged Element to HTML List in JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for JavaScript Language
JavaScript Tutorials
Download
You must upgrade your account or reply in the thread to view hidden text.