The goal of the program is to show a number of questions in various text fields when the user hits a button, and to show the answers to the questions when the user hits a separate button. I am using self created objects to hold the values for both questions and answers.
The following is the Object:
I use a random number times the max number of items to choose which question to use. This is the following:Code:var question_0 = new Object(); question_0.question1 = new String("What are the processor speeds for a Classic Pentium?"); question_0.answer1 = new String("60MHz-200MHz"); question_0.question2 = new String("What are the system bus speeds for a Classic Pentium?"); question_0.answer2 = new String("60MHz, 66MHz"); question_0.question3 = new String("How much cache does the Classic Pentium have?"); question_0.answer3 = new String("16K L1 Cache");
When the user hits the button, it calls this function:Code:function createRandom() { random = Math.round(Math.random() * max_questions); }
first_question, second_question, and third_question are text boxes within the formQuestion form.Code:function randomQuestion() { createRandom(); var showQuestion = "question_"+random; document.formQuestion.first_question.value = showQuestion.question1; document.formQuestion.second_question.value = showQuestion.question2; document.formQuestion.third_question.value = showQuestion.question3; }
The issue is this. When I put "question_0.question1" it shows the value successfully. When I try to use showQuestion or the equivalent in the text box line, it gives me an undefined value.
I'm not sure what the issue is, and would appreciate any possible help. Thank you.
Cheers.
-Alan


Reply With Quote

Bookmarks