Solved

VBScritp loop through checkboxes

Posted on 2006-11-07
3
966 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now