Jump to content

How can I cycle through form's elements?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
I have a form with 40 input fields to upload files.
I want to disable all the fields but the first and I don't want to put 39 instructions to do that.
How can I cycle through all those fields?

Fileds' names are img1, img2, img3,... , img40.
I'm trying with this code, but it doesn't work
var form = document.getElementById("add");
var i;
var image;
for(i=2;i<41;i++) {
    image = "img"+i;
    form.image.disabled = true;
}


#2
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Solved using
form[image].disabled = true;




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users