Click to See Complete Forum and Search --> : Accepting an array as function return value


JKJ
04-20-2003, 01:20 PM
Hi!

I am trying to read the contents of an array into a HTML listbox and am encountering problems.

First I created a COM object in VB with specific functions I need. One of these functions returns an array with which I would like to fill an HTML listbox in an asp page. I am retrieving the array by mouse click on a button in the asp page, therefor I have written a function in Javascript.

<script language="javascript">
function GetTaglist()
{
var f2 = document.forms("TagSearch");

var COMTag = new ActiveXObject("xIMSRG.clsPIData");
var taglist = new Array();
taglist = COMTag.GetTagList("T01037","cd*");

for(var i=0; i<taglist.length; i++)
{
var opt = document.createElement("OPTION");
opt.text = taglist[i];
opt.value = taglist[i];
f2.searchlist.add(opt);
}
}
</script>

I assign the returned array to my array taglist but when checking this variable it appears to be "undefined". It seems I cannot catch the returned array correctly.

Does anyone know how to accept a returned array in Javascript?

Many thanks!

JKJ

khalidali63
04-20-2003, 01:24 PM
var nArray = getArray();

function getArray(){
var narr = new Array(1,2,3,4,5);
return narr;
}
nArray above will have the values in the function where narr is created.

Is that what you are looking for?

JKJ
04-20-2003, 03:07 PM
hello khalidali63,

Your function does exactly what my function GetTagList(...) does: fill and return an array. It is the part "var nArray = getArray();" or as in my case "taglist = COMTag.GetTagList("T01037","cd*");" that does not work.

The array variable "taglist" should be an array filled with the array elements as returned by the COM object function GetTagList(...).

I think that I still have an error in the way I am trying to read the array elements into the array variable "taglist".

I hope I could clarify my question :))

JKJ

khalidali63
04-20-2003, 04:15 PM
this could only lead to one thing...your array is not being created properly ..