Monday, 27 June 2011

Post a form using JavaScript


We normally post a form with Submit button but we can also post a form using JavaScript.
We can use image or simple hyperlink to post a form using this method.

Just  Create a simple HTML page using this code and change the form action and view in browser.


<html>
<head>
<title>
Programing Tutorial by Anurag
</title>
<script language="javascript">
function formsubmit()
{
 document.formName.submit();
}
</script>
</head>
<form name="formName" method="get" action="page2.htm">
Name:<input type="text" name="name">
<a href="#" onclick="formsubmit();">Click Here to submit</a>
</form>
<body>
</body>
</html>

When you test it in your browser yow will see that your form will be posted and posted data will be seen in url of the page2.htm.

Saturday, 25 June 2011

Change the Style with jQuery

This is a basic tutorial, written to help you get started using jQuery.
This tutorial shows you how you can do some special effect using jquery.
Download a copy of jquery from here.



Just start by creating a new HTML page with the following contents:



<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("#test").width("500px");
 });
});
</script>
<title>jQuery Programming Tutorial by Anurag</title>
</head>
<body><button>Click me</button>
<div id="test" style="background-color:#B6FFA4;height:20px;width:240px">Welcome To Programming Tutorials</div>
</body>
</html>


You can test it, just click on Click me button in this HTML page and the width of the div will be changed. Yo can do more same way.



Friday, 24 June 2011

Animate a link using Jquery

This is a basic tutorial, written to help you get started using jQuery.
This tutorial shows you how you can do some special effect using jquery.
Download a copy of jquery from here.

Just start by creating a new HTML page with the following contents:


<html>
  <head>
  <title> Jquery Programming Tutorial by Anurag</title>
 </head>
 <body>
   <a href="http://anurag-tutorial.blogspot.com/"> Programming Tutorial by Anurag</a>
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
   <script>
     $(document).ready(function(){
       $("a").click(function(event){
          event.preventDefault();
 $(this).hide("slow");
       });
     });
   </script>
 </body>
 </html>

You can test it, just click on hyper link in this HTML page and it will disappear with animation.

Thursday, 23 June 2011

Java Program take no from user and print the sum of even and odd nos.

Open notepad or any text editor and type this code.

import java.io.*;

class sumeo
   {
     public static void main(String args[]) throws IOException
      {
        BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
        String a;
        System.out.print("Enter a No: ");
        a=ob.readLine();
        int b=Integer.parseInt(a);
            int even=0,odd=0;
        for(int i=1;i<=b;i++)
        {
                        int c=i%2;
            if(c==0)
                        {
                        even=even+i;
                        }       
                        else
                        {
                        odd=odd+i;
                        }
            }
         System.out.println("Sum of even nos. is:  "+even);
           System.out.println("Sum of odd nos. is:  "+odd);
  }
}



and save this file as sumeo.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your  program by typing  javac sumeo.java
Now the program will be compiled.
Now Run your program by typing  java sumeo
The output of the above program will be like this.





Java Program to Print the Fibonacci series up to desired no

Open notepad or any text editor and type this code.

import java.io.*;
  class fibonacci
   {
    public static void main(String args[]) throws IOException
      {
      BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
      System.out.print("Enter the length of series: ");
      String d=ob.readLine();
      int j=Integer.parseInt(d);

        int a,b,c;
        a=0;
        b=1;
        c=0;
        System.out.println(a);
            System.out.println(b);
        for(int i=0;i<(j-2);i++)
         {
              c=a+b;
          System.out.println(c);
          a=b;
          b=c;
         
         }
       }
   }


and save this file as fibonacci.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your  program by typing  javac fibonacci.java
Now the program will be compiled.
Now Run your program by typing  java fibonacci

The output of the above program will be like this.




Java Program to takes value from user and finds its factorial


Open notepad or any text editor and type this code.

import java.io.*;

class fact
  {
    public static void main(String args[]) throws IOException
     {
        BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the no.: ");
        String a;
        int c=1;
        a=ob.readLine();
        int i=Integer.parseInt(a);

        while(i>0)
          {
           c=c*i;
           i--;
          }
            System.out.print("The factorial of "+a+" is: "+c);
      }
    }           

and save this file as fact.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your  program by typing  javac fact.java
Now the program will be compiled.
Now Run your program by typing  java fact

The output of the above program will be like this.

Java Program to make a Simple Calculator


Open notepad or any text editor and type this code.

import java.io.*;

class cal
  {
    public static void main(String args[]) throws IOException
     {  String a,b,c;
        int s;
        BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the 1st no. :- ");
        a=ob.readLine();       
        System.out.println("Enter the 2nd no. :- ");             
        b=ob.readLine();
        System.out.println("Enter the Choice"+"\n"+"1 for Addition"+"\n"+"2 for  
          Subtraction"+"\n"+"3 for Multiplication"+"\n"+"4 for Division");
        c=ob.readLine();
        s=Integer.parseInt(c);
      int r;
        switch (s)
        {     
        case 1:
        r=Integer.parseInt(a)+Integer.parseInt(b);
          System.out.print("result is:  "+r);
          break;
        case 2:
        r=Integer.parseInt(a)-Integer.parseInt(b);
          System.out.print("result is:  "+r);
          break;
        case 3:
        r=Integer.parseInt(a)*Integer.parseInt(b);
          System.out.print("result is:  "+r);
          break;
        case 4:
        r=Integer.parseInt(a)/Integer.parseInt(b);
          System.out.print("result is:  "+r);
          break;
        default:
        System.out.print("Wrong Choice");
        break;
        }
     }
  }    

and save this file as cal.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your  program by typing  javac cal.java
Now the program will be compiled.
Now Run your program by typing  java cal

The output of the above program will be like this.

Java Program to take two values from user and display sum of these values

Open notepad or any text editor and type this code.


import java.io.*;

class userio
   {
     public static void main(String args[]) throws IOException
      {
        BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
        String a,b;
        System.out.print("Enter 1st no: ");
        a=ob.readLine();
        System.out.print("Enter 2nd no: ");
        b=ob.readLine();
        int c=Integer.parseInt(a)+Integer.parseInt(b);
        System.out.println("The Sum is: "+c);
       }
    }    


and save this file as userio.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your  program by typing  javac userio.java
Now the program will be compiled.
Now Run your program by typing  java userio

The output of the above program will be like this.

Make a Simple Image Slide Show in JavaScript

We can make a simple Image Slider in JavaScript.
Just  Create a simple HTML page using this code and view the result.

<html>
<head>
<title>Simple Slide</title>
</head>
<script language="javascript">
// make a array of images and pass the location of every image.
var myPix = new Array("images/1.jpg", "images/2.jpg", "images/3.jpg");
var thisPic = 0;
function goPrevious() {
     if (document.images && thisPic > 0) {
          thisPic--;
          document.myPicture.src = myPix[thisPic];
     }
}
function goNext() {
     if (document.images && thisPic < 2) {
          thisPic++;
          document.myPicture.src = myPix[thisPic];
     }
}
</script>
<body>
<img src="images/0.jpg" name="myPicture"><br>
<a href="javascript:goPrevious()">Previous</a>
<a href="javascript:goNext()">Next</a>
<body>
</html>

When you test it in your browser yow will see something like this:





Find the sum of the digits

A simple program to show How to find the sum of the digits from 1 to desired digit using JavaScript.
Create a simple HTML page using this code and view the result.

<html>
<head>
<title>Sum of Nos</title>
</head>
<script language="javascript">
function findsum(num) {
     var i, sum = 0;                 
     for (i = 1; i <= num; i++) {
     sum += i;            
     }
      alert("The sum of the digits from 1 to "+ num + " is:\n\n\t " + sum);

}
</script>
<body>
JavaScript Program - Find the sum of the digits.
<form name="adddigits">
     The sum of the digits from 1 to:
     <input type="text" name="num">
     <input type="button" value="Calculate" onClick="findsum(adddigits.num.value)">
</form>
</body>
</html>

When you test it in your browser yow will see something like this:

Wednesday, 22 June 2011

Reduce PDF file size in Adobe Professional

Some times we notice that the size of a pdf file becomes very large due to graphics and images. If You want to reduce its size just Follow these steps.
  • Open your PDF in Adobe Professional
  • Click File -> reduce File Size
  • Save the file.
It reduces the file size, but we want more reduced size, so do a trick
  • Open again previously saved PDF file in Adobe Professional
  • Now save the file compatible for Advanced version say Ver. 7
  • Now again open the file and Save again in less Advanced  version say Ver. 4
Now we have done. Check the file size. It's size has been reduced near about 40 % more.

Enjoy .

Write a Program to use if - else in Java

Open notepad or any text editor and type this code.

public static void main(String args[])
  {
  int a=5,b=8;
      System.out.print("2 nos. are: "+a+" and "+b+"\n");
      if(a>b)
       {
        System.out.print("Bigger no is:"+a);
        }
      else
       {
      System.out.print("Bigger no is:"+b);
       }
   }
}

and save this file as example.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your  program by typing  javac ifelse.java
Now the program will be compiled.
Now Run your program by typing  java ifelse

The output of the above program will be like this.

Write a Simple Java Program

First of all download Java SDK from here. Then install it.
Now open notepad or any text editor and type this code.


class example
{
  public static void main(String args[])
  {
   System.out.println("ANURAG");
   }
 }

and save this file as example.java in the bin directory (c:\j2sdk1.4.2\bin).

Now open command prompt and go to your Java directory.
Now compile your first program by typing  javac example.java
Now the program will be compiled.
Now Run your program by typing  java example

The output of the above program will come like this.