Monday, November 16, 2015

Positive and Negative Number Checker in JavaScript

A simple program that I wrote using JavaScript and HTML forms to accept a number from the user and then the program will check and determine if the given number is positive or number.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.



Program Listing

<html>
<style>
body,p {

  font-family:arial;
  font-size:16px;
 }
</style> 
<body>
<h3> Positive and Negative Number Checker </h3>
<br/>Enter a Number 
<input type="text" id="num_value" name="num_value" size="5">
<br><br>
<button onclick="check_number()">Check Number</button>
<br><br>
<p id="demo"></p>
<script>
  function check_number() {
    var  num_value= document.getElementById("num_value").value;
   
    if (num_value >=0 ) {
  result =  num_value + " is a Positive Number.";
 }
else  {
   result =  num_value +" is a Negative Number.";
}
   
    document.getElementById("demo").innerHTML = result;
  }
</script>
</body>
</html>

Thursday, November 12, 2015

Simple Form Validation in JavaScript

A simple form validation that I wrote in JavaScript to check if the text fields has already a value prior it will send the data in the server for processing like using ASP.NET, ASP, PHP, PERL to process the given data by the user. The code is very simple for beginners that are new in HTML and JavaScript.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
<head>
<title>Form Validation</title>
<style type="text/css">
p,body {
  font-family:arial;
  font-size:20px;
 }

</style>
<script type="text/javascript">

function validate( form )
{
var email_format = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
var phone_format = /^\+?([0-9]{2})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;  

  var fname=form.FirstName.value;
  var lname=form.LastName.value;
  var email=form.Email.value;
  var phone=form.Phone.value; 
  var address=form.Address.value;

var error=document.getElementById('error');

// checking for first name
if(fname==""){
error.innerHTML="* Please enter your first name.";
document.getElementById('FirstName').focus();
return false;

// checking for last name

 if (lname==""){
error.innerHTML="* Please enter your last name.";
document.getElementById('LastName').focus();
return false;

// checking for email address


  if (email==""){
error.innerHTML="* Please enter a valid email address.";
document.getElementById('Email').focus();
return false;
}

 if (!email.match(email_format) ) {
       error.innerHTML="* Please enter a valid email address.";
       document.getElementById('Email').focus();
        return false;
    }

if (!phone.match(phone_format) ) {
       error.innerHTML="* Please enter a valid telephone number.";
       document.getElementById('Email').focus();
        return false;
    } 

// checking for address

 if (address==""){
    error.innerHTML="* Please enter your home address.";
    document.getElementById('Address').focus();
    return false;
   }

}
</script>
</head>

<body>
Form Validation
<form name="form" method="post" onsubmit="return validate(this);">

<table cellspacing="6" cellpadding="4" border="0">
        <tr>
          <td align="right">
            First Name
          </td>
          <td>
            <input type="text" name="FirstName" id="FirstName" />
          </td>
        </tr>
        <tr>
          <td align="right">
            Last Name
          </td>
          <td>
            <input type="text" name="LastName"  id="LastName"/>
          </td>
        </tr>
        <tr>
          <td align="right">
            Email
          </td>
          <td>
            <input type="text" name="Email" id="Email" />
          </td>
        </tr>
        <tr>
          <td align="right">
            Phone
          </td>
          <td>
            <input type="text" name="Phone" id="Phone" />
          </td>
        </tr> 
        <tr>
          <td align="right">
            Address
          </td>
          <td>
            <textarea name="Address" id="Address" cols="23" rows="5" ></textarea>
          </td>
        </tr>
 <tr> &nbsp;</tr>
           <tr>
          <td align="right"></td>
 <td>
            <div id="error"> </div>
</td>
        </tr>
        <tr>
          <td align="right"></td>
          <td>
            <input type="submit" value="Submit" />
          </td>
        </tr>
</table>
    </form>
</form>
</body>
</html>



Divisible By Five in JavaScript

A simple program that will ask the user to give a number our program will check if the given number by our user is divisible by five or not using JavaScript as our programming language.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
 <head>
    <title>
 Divisible By Five
 </title>
 </head>
 <style>
        h3 {
    font-family:arial;
    }
</style>  
 <body>
  <h3> Divisible By Five</h3>
<script>
  var value_number = Number(prompt("Enter a Number : "));
 
   if(value_number % 5 == 0)
        {
            document.write("<font face='arial' size='4'> ");
document.write("The number  " +value_number+
" is divisible by 5. </font>");
        }
        else
        {
            document.write("<font face='arial' size='4'> ");
document.write("The number " + value_number+ 
" is not divisible by 5. </font>");
        }
   </script> 
  </body>
 </html>

Compounded Interest Solver In JavaScript

A simple program that I wrote in JavaScript programming language that will compute the compounded interest rate from the money being borrowed by the person. The code is very simple and very easy to understand. I intended my work for beginners in JavaScript programming.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing


<html>
 <head>
    <title>
 Compounded Interest Solver
 </title>
 </head>
 <style>
        h3 {
    font-family:arial;
    }
</style>  
 <body>
  <h3> Compounded Interest Solver</h3>
<script>

 var principal=0,years=0,rate=0;
   principal = 10000;
   years  = 10;
   rate = .05; 
   
 document.write("<font face='arial' size='4'> ");
 document.write("Principal Amount    :  Php " + principal + "</font><br>");
  document.write("<font face='arial' size='4'> ");
  document.write("Years    : " + years + "</font><br>");
  document.write("<font face='arial' size='4'> ");
  document.write("Interest Rate : " + rate + "</font><br>");
  document.write("<font face='arial' size='4'> ");
  document.write("<br>");
  document.write("Total Amount Compounded over the " + years +" years.</font>");
  document.write("<br><br>");
   for(x=1; x<=years; x++) {
amount = parseFloat(principal) * Math.pow(1+parseFloat(rate),x);
    document.write("<font face='arial' size='4'> ");
document.write("Year " + x  + " : Php "  + amount.toFixed(2) +"</font><br>");
}
  </script> 
  </body>
 </html>

Maximum of Two Numbers in JavaScript

In this article I will share with you a simple program that I wrote in JavaScript that will check and determine which of the two numbers given by our user is the highest or bigger it only uses if - else statement in comparing which of the two number is much bigger.  I intended my work for beginners in JavaScript programming.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output

Program Listing

<html>
 <head>
    <title>
 Maximum Between Two Numbers
 </title>
 </head>
 <style>
        h3 {
    font-family:arial;
    }
</style>  
 <body>
  <h3> Maximum Between Two Numbers </h3>
<script>
  var first_number = Number(prompt("Enter First Number : "));
  var second_number = Number(prompt("Enter Second Number : "));

   if(first_number > second_number)
        {
            document.write("<font face='arial' size='4'> ");
document.write("The " +first_number+
" is much bigger than " + second_number + ".</font>");
        }
        else if (second_number > first_number)
        {
            document.write("<font face='arial' size='4'> ");
document.write("The number " + second_number+ 
" is much bigger than " + first_number + ".</font>");
        }
   </script> 
  </body>
 </html>

Mortgage Calculator in JavaScript

In this article I would like to share with you a simple program that I wrote using JavaScript to compute for the mortgage loan of the person. This program is very simple and easy to understand. I hope this program is very useful in your study how to program in JavaScript.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
 <head>
    <title>
Mortgage Calculator
</title>
 </head>
    <style>
        h3 {
    font-family:arial;
    }
</style> 
 <body>
  <h3> Mortgage Calculator </h3>
  <script>
  // This is a basic mortgage calculator. It calculates your monthy payment.
  
  var principal_amt = parseFloat(prompt("Enter Principal Amount : "));
  var rate = parseFloat(prompt("Enter Yearly Interest Rate : "));
  hold_rate=rate;
  rate = rate/100/12;
  
  var terms = Number(prompt("Enter Term (years): "));
  var hold_terms = terms;
  
  terms = terms * 12;
  
  var amt_solve = (principal_amt * rate) / (1-Math.pow(1+rate, -terms));
  var payment_results = amt_solve.toFixed(2);
  
  document.write("<font face='arial' size='4'> ");
  document.write("Principal Amount Loaned   :  Php " + principal_amt + "</font><br>");
  document.write("<font face='arial' size='4'> ");
  document.write("Yearly Interest Rate      : " + hold_rate.toFixed(2) + "</font><br>");
  document.write("<font face='arial' size='4'> ");
  document.write("Terms of Payments (Years) : " + hold_terms + "</font><br>");
  document.write("<font face='arial' size='4'> ");
  document.write("Amount to be Paid Monthly :  Php " + payment_results +".</font>");
  </script>
  </body>

 </html>

Thursday, October 29, 2015

Payroll in JavaScript

A simple payroll program that I wrote in JavaScript to compute the salary of the employee. The code is very simple and easy to understand.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head>
  <title>Swapping of Numbers</title>
</head>
<style>
h3 {
   font-family:arial;
   };
</style>
<body>
  <script>
    
var val_1 = parseInt(prompt("Enter First Value : "));
var val_2 = parseInt(prompt("Enter Second Value : "));
    var temp=0;
document.write("<h3> Swapping of Numbers</h3>");
document.write("<h3> BEFORE SWAPPING </h3>");
document.write("<font face='arial' size='3'>");
    document.write(" First Value    : " + val_1 + ".</font><br>");
document.write("<font face='arial' size='3'>");
    document.write(" Second Value   : " + val_2 + ".</font><br>");
 
temp = val_1;
     val_1 = val_2;
     val_2 = temp;
               
    document.write("<h3> AFTER SWAPPING</h3>");
document.write("<font face='arial' size='3'>");
    document.write(" First Value      : " + val_1 + ".</font><br>");
document.write("<font face='arial' size='3'>");
    document.write(" Second Value     : " + val_2 + ".</font><br>");

document.write("<h3> End of Program </h3>");
</script>
</body>

</html>

Swapping of Two Numbers in JavaScript

This sample program will ask the user to enter two numbers and then our program will enter change the arrangement of two numbers.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head>
  <title>Swapping of Numbers</title>
</head>
<style>
h3 {
   font-family:arial;
   };
</style>
<body>
  <script>
    
var val_1 = parseInt(prompt("Enter First Value : "));
var val_2 = parseInt(prompt("Enter Second Value : "));
    var temp=0;
document.write("<h3> Swapping of Numbers</h3>");
document.write("<h3> BEFORE SWAPPING </h3>");
document.write("<font face='arial' size='3'>");
    document.write(" First Value    : " + val_1 + ".</font><br>");
document.write("<font face='arial' size='3'>");
    document.write(" Second Value   : " + val_2 + ".</font><br>");
 
temp = val_1;
     val_1 = val_2;
     val_2 = temp;
               
    document.write("<h3> AFTER SWAPPING</h3>");
document.write("<font face='arial' size='3'>");
    document.write(" First Value      : " + val_1 + ".</font><br>");
document.write("<font face='arial' size='3'>");
    document.write(" Second Value     : " + val_2 + ".</font><br>");

document.write("<h3> End of Program </h3>");
</script>
</body>
</html>

Pound To Kilogram Converter in JavaScript

A simple program that I wrote that will ask the user to enter a value in pound and it will convert into kilogram weight equivalent. The program is very simple and easy to understand.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
<head>
  <title>Pound To Kilogram Converter</title>
</head>
<style>
h3 {
   font-family:arial;
   };
</style>
<body>
  <script>
    var pound = parseInt(prompt("How Many Pound(s) : "));
var solve_kilogram=(pound * 0.453592);

document.write("<h3> Pound To Kilogram Converter</h3>");
document.write("<font face='arial' size='4'>");
    document.write(" The equivalent  of " + pound + " pound(s)");
document.write(" is " + solve_kilogram.toFixed(2) + " kilogram(s).</font><br>");
document.write("<h3> End of Program </h3>");
</script>
</body>
</html>