Hi All,
I am going to validating a checkbox which is created dynamically that means the field name is not fixed everytime .Here is my html code
and the javascript code isHTML Code:<tr> <td class="Cat" bgcolor="#cccccc" style="padding-left:10px; border-bottom:1px solid #ffffff;">Computer <span style="color:#fff;">*</span> </td> <td style="padding-left:10px;"> laptop <input type="checkbox" name="n5_Computer[]" id="n5_Computer[]" value="laptop" /> pc <input type="checkbox" name="n5_Computer[]" id="n5_Computer[]" value="pc" /> notebook <input type="checkbox" name="n5_Computer[]" id="n5_Computer[]" value="notebook" /> iphone <input type="checkbox" name="n5_Computer[]" id="n5_Computer[]" value="iphone" /> </th> </tr> <tr> <td class="Cat" bgcolor="#cccccc" style="padding-left:10px; border-bottom:1px solid #ffffff;">Location <span style="color:#fff;">*</span> </td> <td style="padding-left:10px;"> India <input type="checkbox" name="n5_Location[]" id="n5_Location[]" value="India" /> saudi <input type="checkbox" name="n5_Location[]" id="n5_Location[]" value="saudi" /> kolkata <input type="checkbox" name="n5_Location[]" id="n5_Location[]" value="kolkata" /> </th> </tr>
The problem is always the checkbox_choices becomes 0 though if I select.Code:var checkbox_choices = 0; var getcid = "n5_"+en[i]; alert(getcid); var selection =document.getElementsByName(getcid).length alert(selection); // Loop from zero to the one minus the number of checkbox button selections for (var counter = 0; counter < selection; counter++) { // If a checkbox has been selected it will return true // (If not it will return false) if (document.form3[getcid][counter].checked) { checkbox_choices = checkbox_choices + 1; } } if(checkbox_choices == 0) { emptyfields += "\n - Please select :" + clarr[i]; }
I think the problem is in this line
Please suggest,Code:var selection =document.getElementsByName(getcid).length
Raj


Reply With Quote

Bookmarks