Solved

VBScritp loop through checkboxes

Posted on 2006-11-07
3
975 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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.

691 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