Solved

VBScritp loop through checkboxes

Posted on 2006-11-07
3
971 Views
Last Modified: 2009-07-29
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
     Next

I get an error "Object property or method 'document.forms(...).inField' is not supported"
0
Comment
Question by:YZlat
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 125 total points
ID: 17891991
<form>
<input type=checkbox name=opt1 checked>
</form>
      
<script type="text/vbscript">

For i=1 to 2
      inField="opt"&i
      if document.forms(0).elements(inField).checked then
            MsgBox("hey")
      end if
Next
</script
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17891992
YZlat,

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.

b0lsc0tt
0
 
LVL 30

Expert Comment

by:callrs
ID: 17892056
Demo works. inField is a variable not a literal, so you need to use .elements(inField) not .inField
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Finding (and replacing) text between two strings in Php 7 56
remove border from element 5 77
Animated .jpg? 13 77
compact pure CSS Read More Toggle 4 57
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Read about why website design really matters in today's demanding market.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now