Home Javascript Javascriptexamples JavaScript toLocaleLowerCase method

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript toLocaleLowerCase method

Advertisement
This page discusses - JavaScript toLocaleLowerCase method

JavaScript toLocaleLowerCase method

       

If we want to convert whole string into the lower case letters then we can do this with a single step by calling method toLocaleLowerCase() on the string object. For example if we have a string "Hello Rose India" and we want to convert it into the lower case as "hello rose india" then we can use toLocaleLowerCase() method of JavaScript.

Syntax :

 string_object.toLocaleLowerCase();

Where string_object is that specified string which is to be converted into the lower case regarding the current locale.

Description of code :

To illustrate use of toLocaleLowerCase() method we have created a HTML page into which we have created an input text box which takes the character or string by the user that is to be converted. We have also created a button "Convert text to lowercase" and it calls the function lowerCaseText() which is defined in between the pair of <script></script> tags.

function lowerCaseText()
 {
   var textToConvert = document.getElementById('txt').value;
   document.getElementById('txt').innerText = 
                          textToConvert.toLocaleLowerCase(); 
 }

In the above function first line of code creates a variable textToConvert and contains text input value. In the second line of code we have converted the text string and replaced it with the text in the input text box.

<html>
<head>
<title>Convert string to locale's lowercase</title>
<script language="JavaScript">
function lowerCaseText()
 {
   var textToConvert = document.getElementById('txt').value;
   document.getElementById('txt').innerText = 
                          textToConvert.toLocaleLowerCase(); 
 }
</script>
</head>
<body>
<p>&nbsp;</p>
<div style="background: #ff9900; width:'100%';"
       align="center">
  <font color="#0000ff" size="12pt">
	<b>toLocaleLowerCase() Example</b>
  </font>
 </div>
<center>
<div>
Insert any text to Convert
 <p>
   <input type="text" id="txt" />
 </p>
</div>
<input type="button" value="Convert text to lowercase" 
                       onClick="return lowerCaseText();"/>
</center>
</body>
</html>

Output :

Insert text into the text box which is to be converted into the lower case letters and click on the button "Convert text to lowercase"

You can see from the output picture that it has converted the text box value into the lower case.

Download Source Code

       

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: JavaScript toLocaleLowerCase method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com