I'm working on two formats of a web based quiz and I want to make it easier on later revisions, so I'm trying to put the questions and answers in a separate file and then write them to a preformatted html page. I'm using a table inside a form on the html page, and arrays with the question and answer pairs in the separate file. What should my function showquestions( ) look like?
Announcement
Collapse
No announcement yet.
writing into a table inside a form from a .js file
Collapse
X
-
well, um, lessee...
Let's say the questions are loaded into an array of question objects.
Code:function Question (theQuestion, theOptions, theAnswer) { this.question = theQuestion; // a string this.choices = theOptions; // array of strings this.answer = theAnswer; //index of choices array for correct choice. }
Code:<form> <table ...> <script> for (var i=0; i<questionArray.length; i++) { document.write ("<tr><td>" + questionArray[i].question + "<br>"); for (j=0; j<questionArray[i].choices.length; j++) { document.write ("<input type='checkbox' .... onclick=...."> "); document.write (questionArray[i].choices[j] + "<BR>"); } document.write ("</td></tr>"); } </script> </table> </form>
Comment