Using variables when referring to form elements using JS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Starcraftmazter
Forum Commoner
Posts: 45
Joined: Mon Apr 24, 2006 11:36 pm

Using variables when referring to form elements using JS

Post by Starcraftmazter »

Hey guys.

I'm using javascript to loop through all the input textboxes of a form and sent them to nothing. I need to have a loop variable called $i in the name of the input element, however I can't find a way to do that (syntax errors, etc), so I am using the ID of the element - which is ok, but out of curiosity I wonder if it's possible.

Code: Select all

 
        for ($i = 0; $i < 16; $i++) {
            // This doesn't work, because I can't find a way to insert $i into the LHS. 
//         document.program.addr_+$i.value = '';
 
            // This works fine
            document.getElementById("addr_"+$i).value = '';
        }    
 

Thanks!
Post Reply