Javascript String Manipulation using Using toUpperCase and toLowerCase

Guest Posts Paolo Nikko Nuñal

Javascript has plenty of functions that can make your lives easier and in this topic, we will talk about on how you can easily convert any string of characters into lower and uppercase letters. The function we are talking about is using the "toUpperCase()" and "toLowerCase()". This function is pretty much useful in scenarios where users tend to input upper and lower case letters. and you want them to be uniform when you want to store it into a database. One of the most common scenarios that you can find it useful is by registering a username. Most of the time users tend to captialize the first letter of their username, that can be pretty tough to compare most especially when it deals on logging in some details.

<p id="text1">I will be converted to all Upper Case<p>
<p id="text2">I will be converted to all Lower Case<p>
<button onclick="upperCase()"> to UpperCase </button>
<button onclick="lowerCase()"> to LowerCase</button>
<script>
function upperCase()
{
var string = "Hello World";
var string2 = string.toUpper();
document.getElementById("demo").innerHTML=res;
}
function lowerCase()
{
var string = "Hello World";
var string2 = string.toLower();
document.getElementById("text1").innerHTML=res;
document.getElementById("text2").innerHTML=res;
}</script>


The method "toUpperCase()" automatically converts all of your characters to upper case and the method "toLowerCase()" changes your characters to the other way around. That's it, you can apply this one when you submit data and save it over to the database. This is generally useful for registering important data like emails and the like.




Learn HTML5/PHP/AJAX Web Programming from Scratch – An amazing course from Dr. Richard Stibbard. Usually I only promote my own courses, but this course is very impressive, so I cut a deal with Dr. Stibbard … You can also find Richard’s website here