• Archives

  • Archive for the ‘Javascript’ Category

    Looping through the headers in javascript

    Saturday, November 10th, 2007

    Well it is a good thing to look at looping examples to learn it thoroughly:

    example looping through the headers

    <html>
    <body>

    <script type=”text/javascript”>
    for (i = 1; i <= 6; i++)
    {
    document.write(“<h” + i + “><center>welcome to the jungle</center>”)
    document.write(“</h” + i + “>”)
    }
    </script>

    </body>
    </html>

    This will loop through the heading tags using the for event

     Thanks

    krates

    For Loop in javascript

    Monday, November 5th, 2007

    Looping is an essential part of programming you can use looping structure to loop through arrays , variables , etc

    Using it

    <html>

    <head>

    <title>Easytutorial.info for loop in javascript</title>

    </head>

    <body>

    <script type=”text/javascript”>

    var r = 10

    for(i=0;i<=r;i++)

    {

    document.write(“Welcome to easytutorial.info <br>”)

    }

    </script>

    </body>

    </html>

    the above script will print 10 times

    welcome to easytutorial.info


    for(i=0;i<=r;i++)

    understand the above statement

    for (i=0 <!– Assigning 0 to i

    ; <!– Sepration Operator –>

    i < = r <! — Condition –>

    i++ <!– Incrementation –>

    { <!– Inside this bracket the code will be executed>  }

    Using Conditional Statements

    Saturday, November 3rd, 2007

    In JavaScript we have the following conditional statements:

    • if statement – use this statement if you want to execute some code only if a specified condition is true
    • if…else statement – use this statement if you want to execute some code if the condition is true and another code if the condition is false
    • if…else if….else statement – use this statement if you want to select one of many blocks of code to be executed
    • switch statement – use this statement if you want to select one of many blocks of code to be executed

    In this session we will only use the if , else if , else

    Using

    i=0
    if (i>10){
    
    document.write("i is more than 10")
    
    }
    else if (i=0)
    {
    document.write("i is equal to 0")
    }
    else {
    document.write("i is lol")
    }

    In the above code first we declare a variable named ( i )

    Then we check with the if statement that is i is greater then 10 if the statement is true

    The browser will print

    i is more than 10

    If the statement is not true it goes to the else if

    and the condition in the else if is checked and if it is true it will print

    i is equal to 0
    
    

    Now when if and else if both are false then the else statement gets executed and prints

    i is lol

    Thanks

    krates

    Creating autoclear form fields

    Thursday, November 1st, 2007

    Whenever you work with forms there is value field like you are working in a text field you will write

    <input type=”text” name=”textfield” value=”welcome” />

    Now that value is displayed adressing you what you have to write there

    How the user will use it he will click on the field and delete the string welcome and write what he has to now if you want not to pain the user using a autoclear field using jscript

    using onFocus

    Syntax

    <input type=”text” name=”n” value=”Your message” onFocus=”if(this.value==’Your message’)this.value=’ ‘;”>

    Note this thing is case sensitive

    means

    Welcome is not equal to welcome

    when changing the welcome string note this point

    And you are done