Wednesday, October 5, 2016

Positive and Negative Number Checker in JQuery

Here is a very simple program that I wrote using JQuery that will ask the user to give a number and then our program will check and determine whether the given number is a positive number or negative number 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>
<title> Positive or Negative Number Checker in JQuery </title>
<script src="jquery.js"></script>
<style>
body {
 font-family: arial;
 font-size:15px;
 font-weight:bold;
 }

 .input_bold {
    font-weight: bold;
font-size:15px;
color: red;
}
</style> 
<script>
$(document).ready(function(){

 $("#check_it").click(function(){
  var num = $("#num_value").val();

  if(jQuery.isNumeric(num) == false){
        alert('Please enter numeric value');
$('#num_value').val('');
$("#results").val('');
        $('#num_value').focus();
     }
  else if (num>= 0)
{
remarks = num+ " is a Positive Number.";
$("#results").val(remarks);
}
  else {
remarks = num+ " is a Negative Number.";
$("#results").val(remarks);
      }
 });

   $("#clear").click(function(){

   $("#num_value").val('');
   $("#results").val('');
   $("#num_value").focus();
    
  });
  
  
 });


 </script>
</head>
<body>
<form>
Give a Number
<input type="text" id="num_value" size="3"autofocus/><br><br>

The result
<input type="text" id="results" class="input_bold" size="30" readonly/><br>
<br><br>
<button type= "button" id ="check_it">Check </button>    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button type= "button" id ="clear">Clear </button>    
</form>
</body>
</html>

No comments:

Post a Comment