In Association with Amazon.in   Flipkart

Thursday, August 22, 2013

HTML Fieldset And Legend Tags Example

Example:

<fieldset style=" width:350px; background-color:#CCF">

  <legend style="padding:4px 12px; border:double; background-color:#CC9">Login</legend>
    <table width="350" height="138" border="0" cellpadding="12" cellspacing="6" >
        <tr>
                <td>Username:</td>
            <td><input type="text" name="unm" placeholder="User Name" /></td>
        </tr>
        <tr>
                <td>Password:</td>
            <td><input type="password" name="pwd" placeholder="Password" /></td>
        </tr>
        <tr>
          <td colspan="2" align="center" valign="middle">
          <input type="submit" value="Login" />
          </td>
        </tr>
    </table>

</fieldset>


Output:


Login
Username:
Password:

Saturday, August 10, 2013

Javascript Do While Loop Example

Do While:  If the given condition is true/false Do Wile Executes at least once.

 

Example:

<body>
    <script>


    t=9;
    i=10;
    do
    {
        document.write("<br/>" + t+ " X " + i + " = " + i*t);   
        i++;
    }while(i>12);
   
    </script>
</body>



OutPut:

9 X 10 = 90



JavaScript While Loop Example

Example:

<body>
    <script>


    t=9;
    i=1;


    while(i<=12)
    {
        document.write("<br/>" + t+ " X " + i + " = " + i*t);   
        i++;
    }
   
    </script>
</body>




Output:


9 X 1 = 9
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45
9 X 6 = 54
9 X 7 = 63
9 X 8 = 72
9 X 9 = 81
9 X 10 = 90
9 X 11 = 99
9 X 12 = 108


JavaScript Continue Statement In For Loop Example

Continue Statement: To Break The Loop temporarily if certain condition is true and re-continue again.

Example:

<body>
    <script>


    // Break in  For Loop


    t=9;


    for(i=1; i<=12; i++)
    {
        if(i%3==0)
            continue;
        document.write("<br/>" + t+ " X " + i + " = " + i*t);   
    }
   
    </script>
</body>


Output:

9 X 1 = 9
9 X 2 = 18
9 X 4 = 36
9 X 5 = 45
9 X 7 = 63
9 X 8 = 72
9 X 10 = 90
9 X 11 = 99

JavaScript Break Statement In For Loop Example

Break Statement: To Break The Loop Permanently if certain condition is true.

Example:

<body>
    <script>


    // Break in  For Loop


    t=9;


    for(i=1; i<=12; i++)
    {
        if(i==6)
        break;
        document.write("<br/>" + t+ " X " + i + " = " + i*t);   
    }
   

    </script>
</body>




Output:

9 X 1 = 9
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45

JavaScript Nested For Loop Example

Nested For Loop:  For Loop Inside Another For Loop

Example:

 <body>
<script>

    x=5; y=9;

    for(i=x; i<=y; i++)
    {


        for(j=1; j<=10; j++)
        {
                document.write("<br/>" + i+ " X " + j + " = " + i*j);   
        }


        document.write("<hr/>");


    }


 </script>
 </body>


Output:

5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50



6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10 = 60

7 X 1 = 7
7 X 2 = 14
7 X 3 = 21
7 X 4 = 28
7 X 5 = 35
7 X 6 = 42
7 X 7 = 49
7 X 8 = 56
7 X 9 = 63
7 X 10 = 70

8 X 1 = 8
8 X 2 = 16
8 X 3 = 24
8 X 4 = 32
8 X 5 = 40
8 X 6 = 48
8 X 7 = 56
8 X 8 = 64
8 X 9 = 72
8 X 10 = 80

9 X 1 = 9
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45
9 X 6 = 54
9 X 7 = 63
9 X 8 = 72
9 X 9 = 81
9 X 10 = 90
 

Javascript For Loop Example

JavaScript For Loop Example:

 For Loop Syntax

     for(assignment; test condition; Inc/Dec)
    {
        --------;
        --------;   
    }  


Example:

    <body>
     <script>
    t=9;
    for(i=1; i<=12; i++)
    {
        document.write("<br/>" + t+ " X " + i + " = " + i*t);  
    }

   <script>
   <body>


Output:

 
9 X 1 = 9
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45
9 X 6 = 54
9 X 7 = 63
9 X 8 = 72
9 X 9 = 81
9 X 10 = 90
9 X 11 = 99
9 X 12 = 108

JavaScript Looping Statements

In JavaScript there are 4 types of  Looping Statements:

  1. For Loop
  2. While Loop
  3. Do While
  4. For In (For displaying  Array elements)
1. For Loop:

Syntax: 
              for(Initialization;  Test Condition; Increment/Decrement)
               {
                 -----------------;
                ------------------;
              }


2. While Loop:

Syntax:
              Initialization;
              while(Test Condition)
             {
                ----------------;
                ----------------;
               Increment/Decrement statement;
           }

3. Do While Loop:

Syntax: 
               Initialization;
              do
              {
                ----------------;
                ----------------;
               Increment/Decrement statement;
             }while(Test Condition);


4. For In Loop: 
For displaying  Array elements)

Syntax: 

          for(var_name in Array_name)

         {
             --------------------;
            ---------------;
        }

Related Posts Plugin for WordPress, Blogger...