Web Analytics Made Easy -
StatCounter writing into a table inside a form from a .js file - CodingForum


No announcement yet.

writing into a table inside a form from a .js file

  • Filter
  • Time
  • Show
Clear All
new posts

  • writing into a table inside a form from a .js file

    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?

  • #2
    well, um, lessee...

    Let's say the questions are loaded into an array of question objects.
    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.
    I'm not sure what-all showQuestions() is supposed to do but I expect the question / table structure will be built upon page load.

      <table ...>
             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=....">&nbsp;&nbsp;");
                   document.write (questionArray[i].choices[j] + "<BR>");
              document.write ("</td></tr>");


    • #3
      Took me long enough

      Thanks for your help RadarBob, it took me a while to figure out how to combine it with the code that I already had.