Friday, August 18, 2017

Count the number of Words Using JQuery

A very simple program that I wrote using JQuery to count the number of words in a given sentence by our user. I admit I love to you with JavaScript specially using it's framework JQuery, AngularJS and others because it is fun and easy to understand. The code is very short and simple to use. I hope guys you will learn from this one.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.







Sample Program Output


Program Listing

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Count the number of Words Using JQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("button").click(function(){
            var words = $.trim($("textarea").val()).split(" ");
            var display_results = words.length;
   document.getElementById("result").innerHTML = display_results +".";
        });
    });
</script>
  <style>
   body {
     font-family:arial;
font-weight:bold;
background-color: lightgreen;
size:12px;
   }
  </style>
</head>
<body>
    <br>
<h2>Count the number of Words Using JQuery</h2>
<br>
    Enter a sentence 
    <textarea cols="50"></textarea>
    <br><br>
    <button type="button" title="Click here to count the number of words in the sentence.">
Ok</button>
<br><br><br>
The number of words in the sentence is <span id="result"></span>
</body>
</html>                                



No comments:

Post a Comment