Tuesday, 16 June 2015

Java Script Tutorial



Loop

A loop describes the process of a software program or script repeats the same instructions or processes the same information over and over until receiving the order to stop. If not handled properly a loop can cause the computer to become slower as it becomes overwhelmed with having to repeat the same steps over and over causing it to get stuck in an endless loop. 

Print A Table Using While Loop

<html>
<head>
      <script language="javascript">
      function table()
      {
         
  
          var ob=t1.value;
            var i=1;
        while (i<=10)
        {
                s1.innerHTML+=ob+"*"+i+"="+(ob*i)+"<br>";
                i++
        }
      }
</script>
</head>
<body>
      <input type="text" id=t1><br /><br />
      <input type="button" value="Print Table" onclick="table()"><br />
      <span id="s1"> </span>
</body>
</html>


Prime Number 

A Prime Number can be divided evenly only by 1, or itself.And it must be a whole number greater than 1.

<html>
<head>
    <title>Girfa : Prime Number Program</title>
     <script language="javascript">
     function Prime()
     {
      
           var ob=t1.value;
           var b=2;
           while (b<ob)
           {
                   if(ob%2==0)
                      break;
                b++;
           }
           if(b==ob)
                s1.innerHTML="Prime";
           else
                s1.innerHTML="Not Prime";
     }
</script>
</head>
<body>
     Enter Number : <input type="text" id="t1"><br /><br />
     <input type="button" value="Check" onclick="Prime()"><br /><br />
     <span id="s1" style="color:Red;font-size:larger"> </span>
</body>

</html>


Getting file size in javascript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Girfa : File size demo</title>
<script language="javascript">
function getFileSize()
{
var fileInput =  document.getElementById("f1");
alert(parseInt(((fileInput.files[0].size/1024)/1024)) + "KB");
}
</script>
</head>

<body>
<h1 align="center">Getting file size using java script</h1><hr />
<center>
Select your file : <input type="file" id="f1" /><br /><br />
    <input type="button" value="Upload" onclick="getFileSize()" />
   
</center>
</body>
</html>