I have a cancel_complaints page in ASP in which list of complaints r coming (2 records come at a time means page navigation).In that page some information is coming in table and i have given a checkbox in one Table column according to records in database table rows are generated.That is multiple checkbox are generated with same name.I have put a validation that if user has selecetd none of checkbox alert message comes.Problem is that when there are more than one row validation is going fine but when only one row remains validation does not goes fine.Below i am giving javascript function that i have used for validation.----------function------------function validatefield(){ var j=0; var lenvar=document.cancel_complaints.chksel.length; //alert(eval(lenvar)); for (i = 0; i < lenvar; i++) {if(document.cancel_complaints.chksel[i].checked) { j=j+1; } } if(j==0) { alert("Please select atleast one checkbox"); return false; } else { return true; document.cancel_complaints.submit(); }}----------in case of one row(i.e only one record i.e only one checkbox) the value of lenvar is undefined and if there are more than one row the value of lenvar comes= (no of checkboxes)i am unable to understand why there is problwm in counting in total no of checkboxes.if somebody has solution then plz tell me.thanks in advance

Questions by kshivani

Showing Answers 1 - 1 of 1 Answers

rajamuna

  • Jul 26th, 2006
 

Try the folowing Javascript Function :

---------------------

function validatefield()
{
var j=0;
var lenvar = 0;
var lenEle = document.cancel_complaints.elements.length;
for (i = 0; i < lenEle; i++)
{
if((document.cancel_complaints.elements[i].type)=="checkbox")
{
 lenvar = lenvar + 1;
}
}


for (i = 0; i < lenvar; i++)
{
 if(lenvar==1)
 {
  if(document.cancel_complaints.chksel.checked)
  {
   j=j+1;
  }
 }
 else if(document.cancel_complaints.chksel[i].checked)
 {
  j=j+1;
 }
}

if(j==0)
{
alert("Please select atleast one checkbox");
return false;
}

else
{
return true;
document.cancel_complaints.submit();
}
}

------------------------

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions