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

JavaScript - Automatically Change Text Properties

truil

PvP Gladiator
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
178
Likes
113
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial we will create a Automatically Change Text Properties using JavaScript. This code can change the text properties into Upper or Lower Case. The code use onkeyup to automatically change the text properties into upper or lower case using toUpperCase() or toLowerCase() special function. This is a user-friendly program feel free to modify it.

We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.

Getting Started:

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

    href

    =

    "https://sourcecodester.com"

    class

    =

    "navbar-brand"

    >

    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 - Automatically Change Text Properties</

    h3

    >
  16. <hr

    style

    =

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

    /

    >
  17. <center

    ><h1

    >

    UPPERCASE</

    h1

    ></

    center

    >
  18. <div

    class

    =

    "col-md-4"

    >
  19. <div

    class

    =

    "form-group"

    >
  20. <input

    type

    =

    "text"

    class

    =

    "form-control"

    onkeyup

    =

    "changeToUpper(this.value)"

    placeholder=

    "Enter here..."

    /

    >
  21. </

    div

    >
  22. </

    div

    >
  23. <div

    class

    =

    "col-md-4"

    >
  24. <div

    class

    =

    "form-group"

    >
  25. <input

    type

    =

    "text"

    class

    =

    "form-control"

    id

    =

    "all_upper"

    readonly

    =

    "readonly"

    /

    >
  26. </

    div

    >
  27. </

    div

    >
  28. <div

    class

    =

    "col-md-4"

    >
  29. <div

    class

    =

    "form-group"

    >
  30. <input

    type

    =

    "text"

    class

    =

    "form-control"

    id

    =

    "first_upper"

    readonly

    =

    "readonly"

    /

    >
  31. </

    div

    >
  32. </

    div

    >
  33. <br

    style

    =

    "clear:both;"

    /

    >
  34. <center

    ><h1

    >

    LOWERCASE</

    h1

    ></

    center

    >
  35. <div

    class

    =

    "col-md-4"

    >
  36. <div

    class

    =

    "form-group"

    >
  37. <input

    type

    =

    "text"

    class

    =

    "form-control"

    onkeyup

    =

    "changeToLower(this.value)"

    placeholder=

    "Enter here..."

    /

    >
  38. </

    div

    >
  39. </

    div

    >
  40. <div

    class

    =

    "col-md-4"

    >
  41. <div

    class

    =

    "form-group"

    >
  42. <input

    type

    =

    "text"

    class

    =

    "form-control"

    id

    =

    "all_lower"

    readonly

    =

    "readonly"

    /

    >
  43. </

    div

    >
  44. </

    div

    >
  45. <div

    class

    =

    "col-md-4"

    >
  46. <div

    class

    =

    "form-group"

    >
  47. <input

    type

    =

    "text"

    class

    =

    "form-control"

    id

    =

    "first_lower"

    readonly

    =

    "readonly"

    /

    >
  48. </

    div

    >
  49. </

    div

    >
  50. </

    div

    >
  51. </

    body

    >
  52. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  53. </

    html

    >

Creating the Script

This code contains the script of the application. This code will automatically change the text into upper or lower case when inputted. 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 directory
  1. function

    changeToUpper(

    string)

    {
  2. if

    (

    string==

    ""

    )

    {
  3. document.getElementById

    (

    'all_upper'

    )

    .value

    =

    ""

    ;
  4. document.getElementById

    (

    'first_upper'

    )

    .value

    =

    ""

    ;
  5. }

    else

    {
  6. document.getElementById

    (

    'all_upper'

    )

    .value

    =

    string.toUpperCase

    (

    )

    ;
  7. document.getElementById

    (

    'first_upper'

    )

    .value

    =

    UpperCaseFirstLetter(

    string)

    ;
  8. }

  9. }

  10. function

    changeToLower(

    string)

    {
  11. if

    (

    string==

    ""

    )

    {
  12. document.getElementById

    (

    'all_lower'

    )

    .value

    =

    ""

    ;
  13. document.getElementById

    (

    'first_lower'

    )

    .value

    =

    ""

    ;
  14. }

    else

    {
  15. document.getElementById

    (

    'all_lower'

    )

    .value

    =

    string.toLowerCase

    (

    )

    ;
  16. document.getElementById

    (

    'first_lower'

    )

    .value

    =

    LowerCaseFirstLetter(

    string)

    ;
  17. }
  18. }


  19. function

    UpperCaseFirstLetter(

    string)

    {
  20. return

    string[

    0

    ]

    .toUpperCase

    (

    )

    +

    string.slice

    (

    1

    )

    ;
  21. }


  22. function

    LowerCaseFirstLetter(

    string)

    {
  23. return

    string[

    0

    ]

    .toLowerCase

    (

    )

    +

    string.slice

    (

    1

    )

    ;
  24. }

There you have it we successfully created a Automatically Change Text Properties 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,341

323,350

Top