• We just launched and are currently in beta. Join us as we build and grow the community.

JavaScript - Autofill Inputs By Dragging

ItsLeoTM

Cyber Evidence Collector
I Rep
0
0
0
Rep
0
I Vouches
0
0
0
Vouches
0
Posts
37
Likes
187
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In this tutorial we will create a Autofill Inputs By Dragging using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is a text-based programming language meant to run as part of a web-based application. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...

Getting started:

First you have to download bootstrap framework, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTf-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navabr navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    JavaScript - Autofill Inputs By Dragging</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <div

    class

    =

    "col-md-6"

    >
  18. <h4

    id

    =

    "PHP"

    draggable=

    "true"

    ondragstart=

    "drag(event)"

    >

    PHP</

    h4

    >
  19. <h4

    id

    =

    "JavaScript"

    draggable=

    "true"

    ondragstart=

    "drag(event)"

    >

    JavaScript</

    h4

    >
  20. <h4

    id

    =

    "C++"

    draggable=

    "true"

    ondragstart=

    "drag(event)"

    >

    C++</

    h4

    >
  21. <h4

    id

    =

    "C#"

    draggable=

    "true"

    ondragstart=

    "drag(event)"

    >

    C#</

    h4

    >
  22. <h4

    id

    =

    "Python"

    draggable=

    "true"

    ondragstart=

    "drag(event)"

    >

    Python</

    h4

    >
  23. </

    div

    >
  24. <div

    class

    =

    "col-md-6"

    >
  25. <div

    class

    =

    "form-group"

    >
  26. <input

    class

    =

    "form-control"

    type

    =

    "text"

    id

    =

    "data"

    ondrop=

    "drop(event)"

    ondragover=

    "dragOver(event)"

    readonly

    =

    "readonly"

    /

    >
  27. </

    div

    >
  28. <center

    ><button

    class

    =

    "btn btn-primary"

    onclick

    =

    "submit();"

    ><span

    class

    =

    "glyphicon glyphicon-save"

    ></

    span

    >

    Submit</

    button

    >

    <button

    class

    =

    "btn btn-success"

    onclick

    =

    "reset();"

    ><span

    class

    =

    "glyphicon glyphicon-refresh"

    ></

    span

    >

    Clear</

    button

    ></

    center

    >
  29. <br

    /

    >
  30. <div

    id

    =

    "result"

    ></

    div

    >
  31. </

    div

    >
  32. </

    div

    >
  33. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  34. </

    body

    >
  35. </

    html

    >

Creating the Script

This code contains the script of the application. This code can drag and drop the data into the corresponded input form. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.
  1. function

    dragOver(

    e)

    {
  2. e.preventDefault

    (

    )

    ;
  3. }

  4. function

    drop(

    e)

    {
  5. e.preventDefault

    (

    )

    ;
  6. var

    data =

    e.dataTransfer

    .getData

    (

    "data"

    )

    ;

  7. document.getElementById

    (

    'data'

    )

    .value

    =

    data;
  8. }

  9. function

    drag(

    e)

    {
  10. e.dataTransfer

    .setData

    (

    "data"

    ,

    e.target

    .id

    )

    ;
  11. }

  12. function

    submit(

    )

    {
  13. var

    data =

    document.getElementById

    (

    'data'

    )

    .value

    ;

  14. if

    (

    data !=

    ""

    )

    {
  15. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    data;
  16. }
  17. }

  18. function

    reset(

    )

    {
  19. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    ""

    ;
  20. document.getElementById

    (

    'data'

    )

    .value

    =

    ""

    ;
  21. }

There you have it we successfully created a Autofill Inputs By Dragging using 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!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

449,193

322,229

322,238

Top