using selct/option

Discussion in 'HTML' started by OzThor, Apr 18, 2004.

  1. OzThor

    OzThor Guest

    I trying to do a webpage that lists 10 items down the left side - on the
    right side there is a drop down list of all the answers for each of the 10
    questions....
    i have that working...
    my problem is passing the answer from each question to a javascript function
    to check there answer given

    below is the code for 1 of the 10 questions as i have it at this time...

    i'm having problems working out just which ver stors the answer given??? and
    if the vale is a number or a string??

    document.write('<tr><td width="50%">')
    document.write(I[1][1])
    document.write('</td><td>')
    document.write('<Select name="+Imatch[1]+">')
    document.write('<option value="??????">??????</option>')

    for (var y=1; y<11; y++){
    document.write('<option
    name="'+I[I[y][4]][2]+'">'+I[I[y][4]][2]+'</option>')
    }
    document.write('</select>')
    document.write('<br>')
    document.write('</td></tr>')

    I[1][1] holds the question
    I[1-10][2] holds the list of 10 possible answers
    I[1][3] & I[1][4] hold 0 at this time and will be used to keep track of if
    it has been answered right etc..

    the y[4][2] is a random value i use to shuffle the possible answers befor
    building the list...

    cold someone please (in plan english) show me how to fix this....
    thanks
     
    OzThor, Apr 18, 2004
    #1
    1. Advertising

  2. OzThor

    mscir Guest

    OzThor wrote:
    > I trying to do a webpage that lists 10 items down the left side - on the
    > right side there is a drop down list of all the answers for each of the 10
    > questions....
    > i have that working...
    > my problem is passing the answer from each question to a javascript function
    > to check there answer given
    >
    > below is the code for 1 of the 10 questions as i have it at this time...
    >
    > i'm having problems working out just which ver stors the answer given??? and
    > if the vale is a number or a string??
    >
    > cold someone please (in plan english) show me how to fix this....


    - How about using separate arrays to keep things simple?
    - I believe it is more efficient to build up a string
    and use a single document.write statement.
    - array elements start at 0, your questions will probably
    start with 1, so if you include numbering you'll want
    to take this into account.

    Enter any number from 0-3 in the function call to see how this works:
    onclick="writetable(3)"


    <script type="text/javascript">

    var Questions = new Array();
    Questions=['Question #1','Question #2','Question #3','Question #4'];

    var Answers = new Array();
    Answers[0] = ['q1 answer 1','q1 answer 2','q1 answer 3','q1 answer 4'];
    Answers[1] = ['q2 answer 1','q2 answer 2','q2 answer 3','q2 answer 4'];
    Answers[2] = ['q3 answer 1','q3 answer 2','q3 answer 3','q3 answer 4'];
    Answers[3] = ['q4 answer 1','q4 answer 2','q4 answer 3','q4 answer 4'];

    var Names = new Array();
    Names = ['name1','name2','name3','name4'];

    function writetable(arrElement) {
    var s1 = '<html><head><body><table><tr><td width="50%">';
    s1 += Questions[arrElement] + '<br><br><br>';
    s1 += '</td><td>';
    s1 += '<Select name="'+Names[arrElement]+'">';
    s1 += '<option value="??????"> Select the Corect Answer </option>'
    for (var y=0; y<Questions.length; y++){
    s1 += '<option name="' + Names[y] + '">'+
    Answers[arrElement][y]+'</option>';
    }
    s1 += '</select><br></td></tr></table></body></html>';
    document.write(s1);
    }
    </script>
    </head>

    <body>
    <form>
    <input type="button" value="Write Table" onclick="writetable(3)">

    Good Luck,
    Mike
     
    mscir, Apr 18, 2004
    #2
    1. Advertising

  3. OzThor

    mscir Guest

    mscir wrote:
    > OzThor wrote:


    I overlooked unique names for each question for each option, and
    separate select names, I think I fixed that here, sorry for the oversight:

    var Questions = new Array();
    Questions=['Question #1','Question #2','Question #3','Question #4'];

    var Answers = new Array();
    Answers[0] = ['q1 answer 1','q1 answer 2','q1 answer 3','q1 answer 4'];
    Answers[1] = ['q2 answer 1','q2 answer 2','q2 answer 3','q2 answer 4'];
    Answers[2] = ['q3 answer 1','q3 answer 2','q3 answer 3','q3 answer 4'];
    Answers[3] = ['q4 answer 1','q4 answer 2','q4 answer 3','q4 answer 4'];

    var SelectName = new Array();
    SelectName=['selectname1','selectname2','selectname3','selectname4'];

    var OptionNames = new Array();
    OptionNames [0] = ['q1name1','q1name2','q1name3','q1name4'];
    OptionNames [1] = ['q2name1','q2name2','q2name3','q2name4'];
    OptionNames [2] = ['q3name1','q3name2','q3name3','q3name4'];
    OptionNames [3] = ['q4name1','q4name2','q4name3','q4name4'];

    function writetable(arrElement) {
    var s1 = '<html><head><body><table><tr><td width="50%">';
    s1 += Questions[arrElement] + '<br><br><br>';
    s1 += '</td><td>';
    s1 += '<Select name="'+SelectName[arrElement]+'">';
    s1 += '<option value="??????"> Select the Corect Answer </option>'
    for (var y=0; y<Questions.length; y++){
    s1 += '<option name="' + OptionNames[arrElement][y] + '">'+
    Answers[arrElement][y]+'</option>';
    }
    s1 += '</select><br></td></tr></table></body></html>';
    document.write(s1);
    }
     
    mscir, Apr 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    777
    GianGuz
    Dec 21, 2004
  2. Cas
    Replies:
    5
    Views:
    819
    Kevin Jones
    Aug 28, 2006
  3. Kevin Blount

    page.aspx?option - how to detect "option"

    Kevin Blount, Nov 28, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    631
    =?Utf-8?B?RWVyYWo=?=
    Nov 28, 2006
  4. Robin
    Replies:
    2
    Views:
    199
    Robin
    Apr 9, 2004
  5. John

    Regex for <option> ... </option>

    John, Jan 23, 2009, in forum: Perl Misc
    Replies:
    10
    Views:
    261
    Eric Pozharski
    Jan 29, 2009
Loading...

Share This Page