Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > using selct/option

Reply
Thread Tools

using selct/option

 
 
OzThor
Guest
Posts: n/a
 
      04-18-2004
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



 
Reply With Quote
 
 
 
 
mscir
Guest
Posts: n/a
 
      04-18-2004
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

 
Reply With Quote
 
 
 
 
mscir
Guest
Posts: n/a
 
      04-18-2004
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','selectn ame4'];

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);
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a Link Button to redirect to another page by using data from =?Utf-8?B?R1REcml2ZXI=?= ASP .Net 1 02-16-2005 07:04 PM
Error page using the Application_Error void dosnt work when using DIV for a please wait message s_erez@hotmail.com ASP .Net 2 12-24-2004 12:11 PM
no code in webform using vs.net, but in webform using notepad timmso ASP .Net 1 12-12-2003 04:30 PM
Using GetOleDbSchemaTable to get SQL Server Field Description - using pete ASP .Net 1 08-29-2003 10:50 AM
Re: MVP? Index error on nested element using System.xml but NOT using msxml??? William F. Robertson, Jr. ASP .Net 1 06-25-2003 08:08 PM



Advertisments