...

View Full Version : Dynamic variables, sort of



pjleonhardt
05-26-2006, 06:33 PM
Hey,
I have a dynamically generated quiz with a variable number of questions. I need to do validation on these questions.. They are named like
question1, question2,question3,...etc.



function grade(b)
{
var numRight = 0;
for(var i=0; i< questions[b].length; i++)
{
var answer = getChecked(document.quizform.question....?);
alert(answer);
if(answer == cor_ans[b][i])
{
numRight = numRight + 1;
}

}
alert(numRight);

}
My question is how do I check each question using the document.quizform.questionX?

Thanks!

Kravvitz
05-26-2006, 08:15 PM
Use the form's elements object and array notation.

var answer = getChecked(document.quizform.elements['question'+b]);

Kor
05-26-2006, 08:40 PM
JSON might help you, i presume
http://www.json.org/

pjleonhardt
05-27-2006, 01:50 AM
thank you both.

That worked perfectly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum