Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a simple question...

    On a form I want to be lazy and just loop thru a subset of checkboxes to see if they've been selected before posting the form. I'm a bit fuzzy after this:

    if (form.Audit_Fed_Over.checked == true) || (form.Audit_State_Over.checked == true)
    {
    for(i=3, i++)
    }

    I want to go thru the 4-8th checkboxs (3-7 on zero index array) and not type in the names or anything -- just hit the checkboxes.

    any ideas?

    TIA

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: a simple question...

    You're missing part of the for loop:

    for(initialization; condition; increment) {}

    You've also got a comma where you should have a semi-colon.

    See here for more details...

    If that didn't answer your question, you'll need to provide more info such as the type of contents in your array (supposedly strings of the object names), etc...

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: a simple question...

    I'm not interested in learning how to do a FOR loop in javascript -- the stuff I posted was 'peudocode' as they say. What I AM interested in is, if it is possible to iterate thru the CHECKBOXES on a form in such a way as to not have to code for the actual name of each box. For example, ona radio button group you can reference the buttons via a zero-based array. if there something similar applicable to checkboxes, or do i have to type names?

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: a simple question...

    Yes, you can create a collection of all the controls in a particular container and check each one's type and do stuff with the checkboxes.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: a simple question...

    would it be too much bother to ask what the syntax is for referring to checkboxes on a form? i have looked around and haven't found a useful snippet yet. OTOH, i went ahead and put together the validation with explicit references to the checkboxes by name, so the question is no longer that urgent -- just curious at this point.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: a simple question...

    Here's an example I made up for you. Nothing fancy. Works in Firefox, and most likely in IE, too.
    Attached Files Attached Files

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: a simple question...

    thanks! this is the code snippet i was hoping for:

    if (colInputs[intCount].type == "checkbox")

    i suppose this is some sort of DOM specification?

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: a simple question...

    I guess so. I create a collection of all elements that are of tag "input," then check each one to see if it is of type "checkbox" before trying to access the checked attribute/property. It is important to consult DOM documentation. Microsoft's site is reasonably good for this due to the way it is cross-linked. The pages also usually report whether the property/method/collection/object is standard or proprietary.

  9. #9
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: a simple question...

    thanks for the response. i have been wondering whether investing in a DOM reference book would be a good idea as javascript can rely on that sort of thing, as your example shows. maybe i will one of these days...

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: a simple question...

    Speaking of DOMs, here's a handy page of references: DOM, Platform Issues, & Cross-Browser DHTML at The Web Standards Project.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •