PDA

View Full Version : Resolved Add a variable to the end of document.forms[0].


bertembra
05-25-2009, 07:26 PM
Hi,

Pritty simple question but just cant get my head round it.

Im passing the var "num" to my function and just want to add it to the end of a DOM element:

E.g.
num = 1;

newNum=document.forms[0].NUM + num;

So it should point to the ID NUM1, but it doesn't :(


Any help appreciated!
Thanks

Rob

Kor
05-26-2009, 12:10 PM
Use square brackets notation.

newNum=document.forms[0].elements['NUM' + num];

or even

newNum=document.forms[0]['NUM' + num];

bertembra
05-27-2009, 10:52 AM
Hi Kor,

Thanks very much it worked perfectly. :)

Bert