iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • I love the code... dot com
    123,729

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Increment a Variable in Javascript

    Increment a Variable in Javascript



    To increment a variable in Javascript is very easy:

    ko=0;

    ko++;

    document.write(ko);


    Which Prints:
    1

    -We create and name our variable ko and give it a value of 0.
    -We increment it, or add one, with plus plus ++
    -We print to the browser with document.write


    Another example in a for loop:

    ko=1;

    for(h=0;h<50;h++) {
    if (h == 2 || h==4) {
    ko++;
    }
    }

    document.write(ko);

    Which Prints:
    3


    -We gave our variable ko a value of 1 to start this time.
    -We created a for loop
    -We said if our variable h equals 2 or 4, the double vertical bars mean or, increment ko.


    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    ko=1;

    for(h=0;h<50;h++) {
    if (h == 2 || h==4) {
    ko++;
    }
    }

    document.write(ko);

    -->
    </script>


    Resources:
    PRINT to Browser with document.write Command in Javascript
    Write a For Loop in Javascript
    If, Else If, and Else in Javascript


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Write a For Loop in Javascript
    Next Article: Use onClick in Javascript





    Creating Web SitesCreating Web Sites

    Matthew MacDonald

    New $19.77

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39

    DojoDojo

    Matthew A. Russell...

    New $26.39

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99

    CSSCSS

    Eric Meyer

    New $29.69

    CSSCSS

    David McFarland

    New $23.09


    Of Interest:
  • Get the Length of a Word or String in Perl
  • Getting Server Time in Perl
  • OPEN and WRITE a Data File in Perl
  • What Environmental Variables are Available
  • Get Query String Using Javascript
  • Increment a Variable in Javascript
  • Change a Form Field with Javascript
  • Opening a REMOTE WINDOW in Javascript
  • HTML Background
  • HTML Space
  • HTML Superscript Text
  • HTML Status

  • More Articles:
  • Passing a Variable or Value to a Subroutine in Perl
  • Renaming a File with Perl's RENAME Function
  • Matching at the Beginning and End
  • Check for Existing File in Perl
  • onClick Javascript
  • Use onLoad to Call More than One Function with Javascript
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Use OnMouseOver in Javascript
  • Use onClick in Javascript
  • HTML Image
  • HTML Body Tag
  • Make a New Paragraph Using HTML
  • HTML Codes

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,490
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:14 EDT