Results 1 to 2 of 2

Thread: javascript var problem

  1. #1
    Join Date
    May 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript var problem

    Hy,

    I was wondering if this is correct.
    I would like to have a different test every time it does the for(test1,test2,test3..).
    This doesn't seem to work.

    for(var i=0;i<9;i++){

    var test + i = document.creatElement('Button');
    }

    any help please ????

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Tr4ffic View Post
    I was wondering if this is correct.
    I would like to have a different test every time it does the for(test1,test2,test3..).
    This doesn't seem to work.

    for(var i=0;i<9;i++){

    var test + i = document.creatElement('Button');
    }

    any help please ????
    Whilst it may be possible to perform exactly what you want (it depends on context), consider using an array instead:

    Code:
    var numButtons = 9,
        tests = [];
    
    for (var i = 0; i < numButtons; ++i)
        tests[i] = document.createElement('button');
    Mike

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
  •