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

JavaScript - Remove Character From String

PSNMAFIA

CISO Advisor
P Rep
0
0
0
Rep
0
P Vouches
0
0
0
Vouches
0
Posts
128
Likes
24
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
In this tutorial we will create a Remove Character From String 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 & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

And this is the link for the jquery that i used in this tutorial https://jquery.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 Character From String</

    h3

    >
  16. <hr

    style

    =

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

    /

    >
  17. <form

    >
  18. <div

    class

    =

    "form-group"

    >
  19. <label

    >

    Remove Character</

    label

    >
  20. <input

    type

    =

    "text"

    id

    =

    "content"

    /

    >
  21. <button

    type

    =

    "button"

    id

    =

    "remove"

    class

    =

    "btn btn-primary"

    >

    Remove</

    button

    >
  22. </

    div

    >
  23. </

    form

    >
  24. <p

    id

    =

    "result"

    ></

    p

    >
  25. </

    div

    >
  26. </

    body

    >
  27. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  28. </

    html

    >

Creating the Script

This code contains the script of the application. This code will remove a specific character inside a string when user input the targeted character and pressed the button. 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. var

    text =

    "For. Open. Multiply itself gathered saying days thing. After. Saying divide rule rule whose may may winged make beast created. Give lights god from. Lesser fifth. Land greater bearing his moving, together seasons beginning deep abundantly deep abundantly green dominion firmament."

    ;

  2. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    text;

  3. document.getElementById

    (

    'remove'

    )

    .onclick

    =

    removeChar;

  4. var

    newText =

    ""

    ;


  5. function

    removeChar(

    )

    {
  6. var

    content =

    document.getElementById

    (

    'content'

    )

    ;
  7. var

    target =

    content.value

    ;

  8. if

    (

    content.value

    ==

    ""

    )

    {
  9. alert(

    "Please enter something first!"

    )

    ;
  10. }

    else

    {
  11. if

    (

    newText ==

    ""

    )

    {
  12. newText =

    text.replace

    (

    new

    RegExp(

    target,

    'g'

    )

    ,

    ""

    )

    ;
  13. }

    else

    {
  14. newText =

    newText.replace

    (

    new

    RegExp(

    target,

    'g'

    )

    ,

    ""

    )

    ;
  15. }

  16. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    newText;

  17. content.value

    =

    ""

    ;
  18. }
  19. }

⚙ Live Demo

There you have it we successfully created a Remove Character From String 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,526

323,535

Top