Hey all,
I have a database of responses to a questionaire - each question has a number of possible responses and each response is stored as a numerical value (ie answer A = 1; answer B = 2 etc)
I'm trying to write a function (in javascript ASP) that will give me an array of objects, each with the name of the response and how many of these responses have been given
I'm wanting to pass the recordset object and the field I'm looking for to this function and do the looping there using a variable in the object call. This is throwing an ADODB.Recordset error '800a0cc1': Item cannot be found in the collection corresponding to the requested name or ordinal error on line 93 which reads:
where 'objRec' is the recordset object and 'tempQuestion' is the fieldname in the database.
Is it possible to use a variable when referencing the recordset object??
Here's the full function code so you can get a better idea of what I'm doing:
Here's how the function is called:
Hope somebody can help!
thanks
Pix
I have a database of responses to a questionaire - each question has a number of possible responses and each response is stored as a numerical value (ie answer A = 1; answer B = 2 etc)
I'm trying to write a function (in javascript ASP) that will give me an array of objects, each with the name of the response and how many of these responses have been given
I'm wanting to pass the recordset object and the field I'm looking for to this function and do the looping there using a variable in the object call. This is throwing an ADODB.Recordset error '800a0cc1': Item cannot be found in the collection corresponding to the requested name or ordinal error on line 93 which reads:
Code:
var tempValue = objRec(tempQuestion);
where 'objRec' is the recordset object and 'tempQuestion' is the fieldname in the database.
Is it possible to use a variable when referencing the recordset object??
Here's the full function code so you can get a better idea of what I'm doing:
Code:
function processResults(objRec, tempQuestion, nameArray) {
var tempArray = new Array;
var maxNum = nameArray.length;
//make sure the tempQuestion is a string
[b]var tempQuestion = new String(tempQuestion);[/b]
//set temporary array with names and zero values
for (i=0; i<nameArray.length; i++) {
tempArray.push(new qObj(nameArray[i],0));
}
//loop through recorset object and test each record's value
while (!objRec.EOF) {
//assign value from the recordset to a temp value
[b]var tempValue = objRec(tempQuestion);[/b]
//loop through to find corresponding value and increment
//object array accordingly
for (i=1; i<maxNum; i++) {
if (i == tempValue) {
tempArray[i].value++;
break;
}
}
}
//send my competed array back
return tempArray;
tempArray = null;
}
Code:
//set the array of possible answers for this question
var answerArray = new Array('Student','Post-Doc','Senior researcher','Clinical scientist','Clinician in training','Clinical consultant','Business Dev','Patient / Carer','Trial support','Charity rep','Nurse','Other');
//set the database field name for this field for ease of reuse in later versions
var thisQuestion = new String('positionHeld');
//build the SQL
SQL = 'SELECT '+thisQuestion+' FROM tbl_2007ConferenceFeedback';
//open the recodset
objRec.Open(SQL,objConn,2);
//pass the recordset, the fieldname and the
//response names to processResults() -
//this should return an array of objects to use for result display
var Q1Array = processResults(objRec, thisQuestion, answerArray);
objRec.Close;
//loop through the responses and print out the values
for (i=0; i<Q1Array.length; i++) {
%><%= Q1Array.name %> = <%= Q1Array.value %><%
}
Hope somebody can help!
thanks
Pix