$$SelectDoc - Problem with one document

I have been using $$SelectDoc to process agents from the web with success, however, I noticed that if there is only one item left on the view, the forms.elements.length for $$SelectDoc returns ‘undefined’ in my js.

If there are two documents in the view it returns 2.

Here is sample code that I have been using. Works fine unless there is only one item left in the view to select. Let me know your thoughts. Thanks.

var cb = document.forms[0].$$SelectDoc;

var selectcount = 0;

var docUNID = new Array();

for(i = 0; i < cb.length; i ++){

if (cb[i].checked){

docUNID[selectcount] = cb[i].value;

selectcount++;

}

}

if (docUNID[0] == null ){

alert(‘No documents Select’);

}

else {

if (docUNID != null ){

result = window.confirm(‘OK to continue’);

//alert(result);

if (result == true) {

document.forms[0].submit();

}

}

}

I reviewed the Forum 4 and 5 but I don’t found any solution.

Any idea?

Thanks in advance.

Subject: $$SelectDoc - Problem with one document

Hi, After alot of searching and modifications, this is what I came up with and it works!!

var oIDs = document.getElementsByName( ‘$$SelectDoc’ );

var selectcount = 0;

var docUNID = new Array();

var check = 0;

//check if if any checkboxs are checked, if not exit

for( var j = 0; j < oIDs.length; j++ )

{

if( oIDs[j].checked )

{

	check = 1;

}

}

if (check == 0)

{

alert ( ‘You did not select any documents, please correct and try again.’);

return false

}

else

{

//will return an array with all check boxes

//process the array to fetch selected UNIDs:

if( oIDs.length )

{

for( var j = 0; j < oIDs.length; j++ )

 {

	if( oIDs[j].checked )

	{

		docUNID[selectcount] = oIDs[j].value;

		selectcount++;

	 }

 }	

 result=window.confirm('You are going to process the selected documents, click OK if you wish to proceed.');

 if (result==true) 

 {

	document.forms[0].SelectedDocs.value = docUNID

	document.forms[0].RunAgent.value = "1"

	document.forms[0].submit();

} 

}

else

{ // just one check box

if( oIDs.checked ) 

 {

 docUNID[selectcount] = oIDs.value;

}

}

}