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

JavaScript - Remove Extension Name

thesexboy

Distributed System Orchestrator
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
77
Likes
72
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this tutorial we will create a Remove Extension Name using JavaScript. This code will dynamically remove the file extension when user click the button. The code itself use onlick() to call a function that will dynamically remove the file extension using dot notation split with a set parameter. This code is free to use you can modify it as your own,

We will be using JavaScript as a server-side scripting language because It allows greater control of your web page behavior than HTML alone. It is embedded in HTML that responsible to allow user to interact with the computer .

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

    =

    "navbar 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 - Remove Extension Name</

    h3

    >
  16. <hr

    style

    =

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

    /

    >
  17. <div

    class

    =

    "col-md-5"

    >
  18. <h3

    >

    List of File Formats</

    h3

    >
  19. <center

    ><button

    class

    =

    "btn btn-primary"

    onclick

    =

    "removeEx('remove');"

    >

    Remove Extension</

    button

    ></

    center

    >
  20. <br

    /

    >
  21. <center

    ><button

    class

    =

    "btn btn-default"

    onclick

    =

    "removeEx('display');"

    >

    Display Extension</

    button

    ></

    center

    >
  22. <br

    /

    ><br

    /

    >
  23. <ul

    style

    =

    "font-size:20px;"

    id

    =

    "result"

    ></

    ul

    >
  24. </

    div

    >
  25. </

    div

    >
  26. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  27. </

    body

    >
  28. </

    html

    >

Creating the Script

This code contains the script of the application. This code will dynamically remove the file extension when the inputs is entered. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.
  1. var

    names=

    [

    "jack.mp4"

    ,

    "image.jpg"

    ,

    "music.mp3"

    ,

    "play.gif"

    ,

    "newChar.png"

    ]

    ;
  2. var

    html=

    ""

    ;

  3. displayList(

    )

    ;

  4. function

    displayList(

    )

    {
  5. html=

    ""

    ;
  6. for

    (

    var

    i=

    0

    ;

    i<

    names.length

    ;

    i++

    )

    {
  7. html+=

    "<li>"

    +

    names[

    i]

    +

    "</li>"

    ;
  8. }

  9. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    html;
  10. }

  11. function

    removeEx(

    str)

    {
  12. if

    (

    str==

    "remove"

    )

    {
  13. html=

    ""

    ;
  14. for

    (

    var

    i=

    0

    ;

    i<

    names.length

    ;

    i++

    )

    {
  15. var

    list=

    names[

    i]

    .split

    (

    "."

    )

    ;
  16. html+=

    "<li>"

    +

    list[

    0

    ]

    +

    "</li>"

    ;
  17. }

  18. }

    else

    if

    (

    str==

    "display"

    )

    {
  19. html=

    ""

    ;
  20. for

    (

    var

    i=

    0

    ;

    i<

    names.length

    ;

    i++

    )

    {
  21. var

    list=

    names[

    i]

    .split

    (

    "."

    )

    ;
  22. html+=

    "<li>"

    +

    list[

    1

    ]

    +

    "</li>"

    ;
  23. }


  24. }
  25. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    html;
  26. }

There you have it we successfully created a Remove Extension Name 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.
 

452,292

323,340

323,349

Top