#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    42
    Rep Power
    12

    PHP and Javascript Dynamic Checkbox Problem


    I have two sets of dynamic checkboxes in PHP which are submited by one form and I was wondering if there is a way that I can validate them with Javascript functions using only that one form??? In other words how can i check that at least one of the checkboxes are checked in each set, and an alert that will tell the user that they need to click on a checkbox.

    The first set of checkboxes includes:

    PHP Code:
    echo "<input type=\"checkbox\" name=\"Courses[]\" value=\"$rows[Crskey]\">\r\n"
    The second set of checkboxes includes:

    PHP Code:
    echo "<input type=\"checkbox\" name=\"Employee[]\" value=\"$row[Empkey]\">\r\n"
    And my form is:

    <form name="form" action="scheduledemp.php" method="POST" onSubmit='return checkform(form);'>

    Again how can i make the user check off at least one box from each of the two sets of checkboxes....if they don't make a choice the form will not submit.....

    Thanks in advance.
  2. #2
  3. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    32
    This is clearly javascript problem, so why are you posting it here?
    And you know I mean that.
  4. #3
  5. film at 11
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Portland, OR
    Posts
    413
    Rep Power
    14
    What's worse, you're duplicating your own thread that you started yesterday.

    To reiterate my two cents: If you name 2 or more checkboxes w/ the same name, you can loop over them as you would loop over any array in javascript. Javascript is nice enough to assume that since you used the same name, you want an array of form elements. I don't know why you're getting a syntax error because you didn't post the offending javascript code.

    Al, fwiw, why respond if you're only going to angrily nag about the choice of forum? At the very least you could do it with a little more tact. Besides, I bet a good percentage of the folks who hang around here can answer this question perfectly well and clearly.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    42
    Rep Power
    12
    Sorry for the duplication, but i'm new at this. I don't quite understand what you are trying to say....what do you mean offending javascript code??
  8. #5
  9. film at 11
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Portland, OR
    Posts
    413
    Rep Power
    14
    You said:
    Tried it but still doesn't work. I get a syntax error.
    That doesn't tell anybody anything. In order for anybody to help you, they need to see the code that generates the syntax error-- the "offending" code that is committing the grievous offense of being broken.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    42
    Rep Power
    12
    was able to figure out the error with the help of Adios. Thanks to all that replied.
  12. #7
  13. film at 11
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Portland, OR
    Posts
    413
    Rep Power
    14
    ahh, I see... you wanted somebody to write your code for you. my bad.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    42
    Rep Power
    12
    No his code was not exactly what i needed but he did provide me with a physical idea of how it was supposed to be done. what i didn't know how to do is to put both sets of checkboxes into one form and plus i have some other fields that i needed to validate as well. don't get me wrong your help was greatly appreciated and i tried three ways of doing it with your advice. Thanks again!!

IMN logo majestic logo threadwatch logo seochat tools logo