ucfirst and ucwords in javascript
by MANIMUTHUPANDI[ Edit ] 2014-06-04 17:21:55
Use this following functions for Ucfirst and Ucwords in javascript.
This defined javascript function will work as PHP built in function works
<script type='text/javascript'>
function javascript_ucfirst(text)
{
text=text.trim()
if (text=='')
return '';
text1=text[0];
text=text.substr(1,text.length)
text=text1.toUpperCase()+text
return text
}
function javascript_ucwords(text)
{
text_arr=text.split(" ")
var output=''
for(s=0;s<text_arr.length;s++)
output+=javascript_ucfirst(text_arr[s])+" "
return output;
}
test_ucwords=javascript_ucwords("mani muthu pandi")
test_ucfirst=javascript_ucfirst("mani muthu pandi")
document.write("Ucfirst==="+test_ucfirst)
document.write("<br />Ucwords==="+test_ucwords)
</script>