Is this possible in Javascript?

Status
Not open for further replies.

Rhaegar

Ars Tribunus Angusticlavius
7,588
I want to reset 12 buttons on the page to their default position. The buttons are named Button1.png through Button12.png The buttons are objects and have the name Button1 through Button12. Is their away to specify the object name in a loop so that I don't have to reset each one separately. For example what would go in the italic space below so that I can set the i-th button object's image to its default position.

Code:
function Button_Reset()
{
  for (var i = 1; i <= 12; i++)
  {
    num = new String(i);
    filename = 'images/Button' + num + '.png';
    document.<I>what can i put here?</I>.src=filename;
  }
}

If I just put Button1 as the object name then it will work fine but ofcourse Button1's image then gets set to equal Button12.png. How do I set the loop up so that Button1's image = Button1.png, Button2's image = Button2.png and so forth.
 
Status
Not open for further replies.