SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    KickMe
    SitePoint Community Guest

    while () not working? - properly asigned

    var counter=1 ;
    while(counter<101)
    {
    counter++;
    }
    have a book here "How to do everything with javascript" ,
    have javascript enabled ,
    puted all html tags in the document , <script> in the body , try within the <head> , not working .
    Pls tell me what is wrong .

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code will run through the loop, but it won't produce any result other than incrementing the counter.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    KickMe
    SitePoint Community Guest
    maybe you are telling me , it will not be outputed in the browser ,well i've had the page loaded with the other things in her , but i can't see the count from 1 to 100 .Even with this piece of code -> document.write("The number is"+counter+"<br />") ; in the { } .Do you know why .

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you show us all of the code that's in the page?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you document.write after the page has loaded you write a new page- the original page, including the script, is gone.Use an alert
    var counter=1 ;
    while(counter<101) {
    alert(counter++);
    }
    Last edited by mrhoo; Jan 20, 2007 at 09:47.

  6. #6
    KickMe
    SitePoint Community Guest
    The alert box works wich is great , and i've figured that this script also works by outputting the result in the browser ,
    var counter=1;
    while(counter<101){
    document.write("This is number"+counter+"<br />") ;
    counter++;
    }
    Thank you all , seems i always find answers in sitepoint.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •