|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Validation of checkboxes... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|