SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot sifuhall's Avatar
    Join Date
    Jun 2001
    Location
    out of the sidehatch
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checkbox validation

    I'm having a bit of trouble with this one.

    I'm using PHP on the backend and the html is dynamically generated.

    There is a arbitrary number of checkboxes on the form, and so PHP can handle them properly they are all named purchasedexams[]

    Here is the code for each checkbox:
    Code:
    <input type="checkbox" name="purchasedexams[]" value="{examid}">
    {examid} is replaced by the actual exam id.

    The problem comes in when I try to use validation on the clientside with javascript to ensure at least one checkbox has been checked.

    Because of the name of the checkboxes (purchasedexams[]) I am having trouble iterating them to ensure at least one is checked because they end with []. However, if I do not name them with [] at the end then PHP will only see the last one that is checked.

    Any suggestions are greatly appreciated.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you having problems iterating the checkboxes? What error do you get? Use document.getElementsByName to get a collection of them.


Bookmarks

Posting Permissions

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