VBScritp loop through checkboxes

I am trying to use VBScript to loop through a number of checkboxes on my form. All the checkboxes named "checnkbox1" through "checkbox10"

Here is my code:

For i=1 to 10
          inField= "opt" & i
          'check if checkbox is checked
          if document.forms(0).inField.Checked then    <--EROR HERE
          end if

I get an error "Object property or method 'document.forms(...).inField' is not supported"
LVL 35
Who is Participating?
callrsConnect With a Mentor Commented:
<input type=checkbox name=opt1 checked>
<script type="text/vbscript">

For i=1 to 2
      if document.forms(0).elements(inField).checked then
      end if
b0lsc0ttIT ManagerCommented:

I may have misunderstood your question but if you have provide each checkbox tag with a name attribute value of checkbox# (# is 1-10) then what is opt# (i.e. inField)?  Try changing opt to checkbox and does that correct the problem?  If I have misunderstood or am missing some info then please elaborate.

Let me know if you have any questions or need more information.

Demo works. inField is a variable not a literal, so you need to use .elements(inField) not .inField
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.