Dear Friends,

 I have implemented multibox, everything is working fine.
 But I would like to validate the checkboxes, my purpose is atleast one
 checkbox will be selected from the user while submitting, if not message
 will be pop up.

 I am implementing javascript(client side) validation,



 My validation.xml contains following code

              <field property="selectedMagazines" depends="required">
                     <arg0   key="interestsForm.selectedMagazines"/>
                 </field>

 I have tried the code, which is posted by "Yuan" as follows in
 validator-rule.xml, but it didn't worked out.


             function validateRequired(form) {
                 var isValid = true;
                 var focusField = null;
                 var i = 0;
                 var fields = new Array();
                 oRequired = new required();

                 for (x in oRequired) {
                     var field = form[oRequired[x][0]];

                     if (field.type == 'text' ||
                         field.type == 'textarea' ||
                         field.type == 'file' ||
                         field.type == 'select-one' ||
                         field.type == 'radio' || // -- true for single
 radio button, Saul Q Yuan ([EMAIL PROTECTED]) 10/28/03
                         field.type == 'checkbox' || // -- true for
 single checkbox, Saul Q Yuan ([EMAIL PROTECTED]) 10/28/03
                         field.type == 'password') {

                         var value = '';
                         // get field's value
                         if (field.type == "select-one") {
                             var si = field.selectedIndex;
                             if (si >= 0) {
                                 value = field.options[si].value;
                             }
                                                 // -- get value for
 checked single radio button or checkbox, Saul Q Yuan
 ([EMAIL PROTECTED]) 10/28/03
                                                 } else if (field.type ==
 "radio" || field.type == "checkbox") {
                                                if
 (field.checked) {
                                                                 value =
 field.value;
                                                         }
                         } else {
                             value = field.value;
                         }

                         if (trim(value).length == 0) {

                             if (i == 0) {
                                 focusField = field;
                             }
                             fields[i++] = oRequired[x][1];
                             isValid = false;
                         }
                     } else if (field.type == "select-multiple") {
                         var numOptions = field.options.length;
                         lastSelected=-1;
                         for(loop=numOptions-1;loop>=0;loop--) {
                             if(field.options[loop].selected) {
                                 lastSelected = loop;
                                 value = field.options[loop].value;
                                 break;
                             }
                         }
                         if(lastSelected < 0 || trim(value).length == 0)
 {
                             if(i == 0) {
                                 focusField = field;
                             }
                             fields[i++] = oRequired[x][1];
                             isValid=false;
                         }
                     } else if ((field.length > 0) && (field[0].type ==
 'radio' || field[0].type == 'checkbox')) {
                         isChecked=-1;
                         for (loop=0;loop < field.length;loop++) {
                             if (field[loop].checked) {
                                 isChecked=loop;
                                 break; // only one needs to be checked
                             }
                         }
                         if (isChecked < 0) {
                             if (i == 0) {
                                 focusField = field[0];
                             }
                             fields[i++] = oRequired[x][1];
                             isValid=false;
                         }
                     }
                 }
                 if (fields.length > 0) {
                    focusField.focus();
                    alert(fields.join('\n'));
                 }
                 return isValid;
             }


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to