JavaScript - Automatically Change Text Properties

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. <nav class="navbar navbar-default">
  8. <div class="container-fluid">
  9. <a href="https://sourcecodester.com" class="navbar-brand">Sourcecodester</a>
  10. </div>
  11. </nav>
  12. <div class="col-md-3"></div>
  13. <div class="col-md-6 well">
  14. <h3 class="text-primary">JavaScript - Automatically Change Text Properties</h3>
  15. <hr style="border-top:1px dotted #ccc;"/>
  16. <center><h1>UPPERCASE</h1></center>
  17. <div class="col-md-4">
  18. <div class="form-group">
  19. <input type="text" class="form-control" onkeyup="changeToUpper(this.value)" placeholder="Enter here..."/>
  20. </div>
  21. </div>
  22. <div class="col-md-4">
  23. <div class="form-group">
  24. <input type="text" class="form-control" id="all_upper" readonly="readonly"/>
  25. </div>
  26. </div>
  27. <div class="col-md-4">
  28. <div class="form-group">
  29. <input type="text" class="form-control" id="first_upper" readonly="readonly"/>
  30. </div>
  31. </div>
  32. <br style="clear:both;"/>
  33. <center><h1>LOWERCASE</h1></center>
  34. <div class="col-md-4">
  35. <div class="form-group">
  36. <input type="text" class="form-control" onkeyup="changeToLower(this.value)" placeholder="Enter here..."/>
  37. </div>
  38. </div>
  39. <div class="col-md-4">
  40. <div class="form-group">
  41. <input type="text" class="form-control" id="all_lower" readonly="readonly"/>
  42. </div>
  43. </div>
  44. <div class="col-md-4">
  45. <div class="form-group">
  46. <input type="text" class="form-control" id="first_lower" readonly="readonly"/>
  47. </div>
  48. </div>
  49. </div>
  50. </body>
  51. <script src="js/script.js"></script>
  52. </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. }
  11.  
  12. function changeToLower(string){
  13. if(string==""){
  14. document.getElementById('all_lower').value="";
  15. document.getElementById('first_lower').value="";
  16. }else{
  17. document.getElementById('all_lower').value=string.toLowerCase();
  18. document.getElementById('first_lower').value=LowerCaseFirstLetter(string);
  19. }
  20. }
  21.  
  22.  
  23. function UpperCaseFirstLetter(string) {
  24. return string[0].toUpperCase() + string.slice(1);
  25. }
  26.  
  27.  
  28. function LowerCaseFirstLetter(string) {
  29. return string[0].toLowerCase() + string.slice(1);
  30. }
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!

Add new comment