#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Forsyth, IL, USA
    Posts
    2
    Rep Power
    0
    Okay here's my dilemma...I'm accessing a Sybase table (using ASP) and returning a series of values from the table based on a query. One of these fields includes a checkbox with the name of UpdSelectedi where i is the value of the loop counter (if 3 returned records then I have three UpdSelected checkboxes: UpdSelected1, UpdSelected2 & UpdSelected3). I want to verify (onSubmit) that only ONE of these checkboxes is selected before passing this selected record to yet another ASP page. How can I successfully get this value and verify this situation?

    The code I'm currently using is as follows (and it doesn't work so well):

    function CheckFields() {
    var i;
    var TotCnt = document.forms[0].TotalCount.value;
    var j=0;

    for (i=1;i < TotCnt; i++) {
    if (document.forms[0].UpdSelected&i.checked) {
    j++;
    }

    if (j > 1) {
    alert("Multiple Market Comparisons selected!nPlease make only one selection.");
    return false;
    }
    else {
    return true;
    }
    }
    }


    THANKS!
    Ttocs
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    Hi,

    First of all, it seems like you should be using <input type="radio"> instead of checkboxes. When you want only one allowable selection, use radio buttons. When you want multiple allowable selections, use checkboxes.

    Secondly, if you're doing validation for security reasons, then you should do only server-side validation. Bad people can easily by-pass client-side validation, by turning JavaScript off or any other number of ways.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Forsyth, IL, USA
    Posts
    2
    Rep Power
    0
    I tried using radio buttons, but because each button or checkbox, for that matter) has a unique name, the standard radio button feature of checking only one at a time doesn't apply. I'm not really validating for security purposes, nor does this data need to be "secure" so I'm just checking to see that the checkbox is checked (and only one is checked) before submitting the form and updating a table (so that another form displays this new data plus additional data related to it).

    Ttocs

Similar Threads

  1. Form validation on checkboxes
    By spiggy72 in forum HTML Programming
    Replies: 12
    Last Post: January 13th, 2004, 02:31 PM
  2. Javascript validation for dynamic checkboxes
    By me_helper in forum JavaScript Development
    Replies: 1
    Last Post: August 16th, 2003, 08:02 AM
  3. checkboxes, validation and PHP
    By whoopah in forum PHP Development
    Replies: 1
    Last Post: January 5th, 2003, 03:46 PM
  4. Replies: 2
    Last Post: August 8th, 2002, 11:23 PM
  5. Replies: 2
    Last Post: February 25th, 2002, 11:10 AM

IMN logo majestic logo threadwatch logo seochat tools logo