Wednesday, October 5, 2016

Count Capital and Small Letters in JQuery

A simple program that I wrote that will ask the user to give a string or a word and then our program will count how many capital and small letters found in the word,string or sentence using JQuery as our JavaScript library.


Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

My email address are the following 
jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

My mobile number here in the Philippines is 09173084360.



Program Listing

<html>
  <head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <title>Count Capital and Small Letters in JQuery</title>
         <style>
        body{
font-family:arial;
font-size:15px;
font-weight:bold;
}  
</style>
        <script>
  $(function(){
$("#count").click(function(){
if (document.getElementById("str").value == '') {
alert("Textbox is Empty !!! Please provide some string.");
document.getElementById("str").value = "";
document.getElementById("upper_str").value = "";
document.getElementById("lower_str").value = "";
document.getElementById("str").focus();
                        }
else {
var str1 = document.getElementById("str").value;
   var numUpper = str1.length - str1.replace(/[A-Z]/g, '').length;  
var numLower = str1.length - str1.replace(/[a-z]/g, '').length;  
                        var result = document.getElementById("upper_str");
var result2 = document.getElementById("lower_str");
                        result.value = numUpper;
result2.value = numLower;
}
       });
});
                   
            $(function(){    
$("#clear").click(function(){
document.getElementById("str").value = "";
   document.getElementById("upper_str").value = "";
   document.getElementById("lower_str").value = "";
   document.getElementById("str").focus();
});
});
        </script>
  </head>
  <body>
      <br><br>
      <h3>Count Capital and Small Letters in JQuery</h3>
  <br>
        Enter a String <input type="text" id="str" name="str" value="" size="30" autofocus/>
        <br><br>
        <input type="button" name="Submit"  id="count" value="Count" title="Click here to count the capital and small letters."/>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="Submit" id="clear" value="Clear" title="Click here to clear the text box."/>
<br><br><br><br>
        Number of Capital Letter(s) is  <input type="text" id="upper_str" name="upper_str" size="3"/>
<br><br>
Number of Small Letter(s) is  <input type="text" id="lower_str" name="lower_str" size="3"/>
  </body>
</html>


No comments:

Post a Comment