Forum Moderators: open

Message Too Old, No Replies

can any one help me to correct my javascript

not going inside for loop when i have one checkbox in an row

         

srins

6:42 pm on Dec 15, 2005 (gmt 0)

10+ Year Member



currently in my script,

function validate(error_message)
{
select_count=0;
alert("validate"+document.myform.TestCase.length);
for(index=0;index<document.myform.TestCase.length;index++)
{
alert("indexvalue"+index);
if (myform.TestCase[index].checked)
{
select_count=select_count+1;
alert("inside"+select_count);
}
}

if (select_count == 0)
{
alert("Please Select the particular TestCase then click" + ' '+ error_message+select_count);
return false;
}
else if (select_count >= 2)
{
alert("Please Select only one TestCase (not more than one)"+ "then click" + ' ' + error_message);
return false;
}
return true;
}

IF I have two testcases displayed in two rows,its working fine.But if i am having only one test case displayed in an row,i am getting an error

validate:undefined

and its showing as
"Please Select the particular TestCase then click" Edit 0);

Its not going inside the for loop ,when i have only one test case in row and showing validate:undefined ,
even if i am having one test case in an row.But if i have more than one testcases,its working fine.

can any one help me in this regard.

Thanks,
srins.

Fotiman

9:04 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




function validate(error_message)
{
var select_count = 0;
var numItems = 1;

if( document.myform.TestCase.length )
{
numItems = document.myform.TestCase.length;
}

alert("validate"+numItems);
for(index=0;index<numItems;index++)
{
alert("indexvalue"+index);
var checked;
if( numItems > 1 )
{
checked = myform.TestCase[index].checked;
}
else
{
checked = myform.TestCase.checked;
}

if( checked )
{
select_count=select_count+1;
alert("inside"+select_count);
}
}

if (select_count == 0)
{
alert("Please Select the particular TestCase then click" + ' '+ error_message+select_count);
return false;
}
else if (select_count >= 2)
{
alert("Please Select only one TestCase (not more than one)"+ "then click" + ' ' + error_message);
return false;
}
return true;
}

srins

10:33 pm on Dec 15, 2005 (gmt 0)

10+ Year Member



Hi Fotiman,

Thanks for changing the code.It is working fine now.

Thanks,
srins.