using selct/option

O

OzThor

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
 
M

mscir

OzThor said:
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
 
M

mscir

mscir said:
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);
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top