I'm trying to make a trivia page for a website ...
take a look at
http://www.geocities.com/bbstory/test/trivia.htm to see what I've got so far...
Getting the info from the radiobuttons works fine, also which items of the left comboboxs are selected ...
but when I'm trying to get the selected items of the right comboboxes, using "exactly" the same code as for the left, I get wrong results (See alerts on website).
so here's my JavaScript code:
<script language="JavaScript">
<!-- Begin
function button1_onclick() //Hauptfunktion, die die Eingaben auswertet
{
var array_Radio = new Array(4); //selected radiobutton
var array_Solution_Radio = new Array("1","2","3","2","1")
; //trivia solutions
var array_combo1 = new Array(4); //selected item - left combo
var array_combo2 = new Array(4); //selected item - right combo
var array_Solution_Book = new Array("hm","hm","hm","hm",
"hm"); //trivia solution left combo
var array_Solution_Character = new Array("1","2","3","2","1")
; //trivia solution right combo
var points=0;
var tmp;
var test=""; //just for debugging
//getting results for radiobuttons
for (x=0;x<5;x++)
{
tmp='radio'+(x+1);
array_Radio[x]=getRadioVal
ue(tmp);
if (array_Radio[x]==array_Sol
ution_Radi
o[x])
{
points=points+10;
}
}
//get combobox value
array_combo1[0]=select1.op
tions[sele
ct1.select
edIndex].v
alue;
array_combo1[1]=select3.op
tions[sele
ct3.select
edIndex].v
alue;
array_combo1[2]=select5.op
tions[sele
ct5.select
edIndex].v
alue;
array_combo1[3]=select7.op
tions[sele
ct7.select
edIndex].v
alue;
array_combo1[4]=select9.op
tions[sele
ct9.select
edIndex].v
alue;
//debugging, which items of the left comboboxes are selected
for (x=0;x<5;x++)
{test=test + array_combo1[x] + " "}
alert(test);
//????????????????????????
??????????
??????????
?????????
//trying to do the same as above for the right comboboxes
//HELP - why doesn't these lines work?
array_combo2[0]=select2.op
tions[sele
ct2.select
edIndex].v
alue;
array_combo2[1]=select4.op
tions[sele
ct4.select
edIndex].v
alue;
array_combo2[2]=select6.op
tions[sele
ct6.select
edIndex].v
alue;
array_combo2[3]=select8.op
tions[sele
ct8.select
edIndex].v
alue;
array_combo2[4]=select10.o
ptions[sel
ect10.sele
ctedIndex]
.value;
test="";
for (x=0;x<5;x++)
{test=test + array_combo2[x] + " "} //I should get the values here !!!!
alert(test);
//????????????????????????
??????????
??????????
??????????
??
/* //comparing solution with selected items
for (x=0;x<5;x++)
{
alert("aussen: " + array_combo1[x] + " - " + array_Solution_Book[x]);
if (array_combo1[x]==array_So
lution_Boo
k[x])
{
alert("innen: " + array_combo2[x] + " - " + array_Solution_Character[x
]);
if (array_combo2[x]==array_So
lution_Cha
racter[x])
{
points=points+10;
}
}
}*/
alert("You've reached " + points + " points");
}
//------------------------
----------
----------
----------
---
function getRadioValue(RadioName) //Aufruf: getRadioValue('radio1')
{
var collection;
collection = document.all(RadioName);
for (j=0;j<3;j++)
{
if (collection[j].checked)
{
return [collection[j].value]; //returns selected item
}
}
}
//------------------------
----------
----------
----------
---
function RemoveItems(id) //remooves items from combobox
{
while(id.length!=0)
{
id.remove(0);
}
}
//------------------------
----------
----------
----------
---
function AddItem(id,str,i) //adds new item to combobox
{ //id: combobox
var oOption = document.createElement("OP
TION"); //str: text of new item
id.options.add(oOption); //i: value of new item
oOption.innerText = str;
oOption.Value = i;
if(i=="0")
{
oOption.selected=true;
}
}
//------------------------
----------
----------
----------
---
function create_list(id,val)
{
RemoveItems(id);
switch (val)
{
case "n/a": AddItem(id,"<not given>",'asdfasdf');
break;
case "hs": AddItem(id,"Susannah Faulconer",'a');
AddItem(id,"Sam Gamble","v");
AddItem(id,"Mitchell Blaine","2");
AddItem(id,"Yank Yankowski","3");
AddItem(id,"Paige Faulconer","4");
AddItem(id,"Calvin Theroux ","5");
AddItem(id,"Joel Faulconer","6");
AddItem(id,"Sam & Susannah","7");
AddItem(id,"Mitch & Susannah","8");
break;
case "hm": AddItem(id,"Honey Moon",0);
AddItem(id,"Dash Coogan",1);
AddItem(id,"Eric Dillon",2);
AddItem(id,"Liz Castleberry",3);
AddItem(id,"Chantal Booker",4);
AddItem(id,"Dash & Honey",5);
AddItem(id,"Eric & Honey",6);
AddItem(id,"Honey & Liz",7);
break;
case "fp": AddItem(id,"Francesca Day",0);
AddItem(id,"Dallie Beaudine",1);
AddItem(id,"Ted Baudine",2);
AddItem(id,"Skeet Cooper",3);
AddItem(id,"Holly Grace Baudine",4);
AddItem(id,"Dallie & Francesca",5);
AddItem(id,"Dallie & Skeet",6);
AddItem(id,"Dallie & Holly Grace",7);
AddItem(id,"Skeet & Francesca",8);
break;
case "kaa": AddItem(id,"Daisy Deveraux",0);
AddItem(id,"Alex Markov",1);
AddItem(id,"Heather Pepper",2);
AddItem(id,"Sheba Quest",3);
AddItem(id,"Max Petrov",4);
AddItem(id,"Brady Pepper",5);
AddItem(id,"Alex & Daisy",6);
break;
case "ihtby":AddItem(id,"Phoebe
Sommerville",0);
AddItem(id,"Dan Calebow",1);
AddItem(id,"Molly Sommerville",2);
AddItem(id,"Ron McDermit",3);
AddItem(id,"Bobby Tom Denton",4);
AddItem(id,"Viktor Szabo",5);
AddItem(id,"Dan & Phoebe",6);
AddItem(id,"Dan & Ron",7);
AddItem(id,"Phoebe & Ron",8);
break;
case "ht": AddItem(id,"Bobby Tom Denton",0);
AddItem(id,"Gracie Snow",1);
AddItem(id,"Suzy Denton",2);
AddItem(id,"Way Sawyer",3);
AddItem(id,"Bobby Tom & Gracie Snow",4);
AddItem(id,"Way Sawyer & Suzy Denton",5);
break;
case "nbbm":AddItem(id,"Jane Darlington",0);
AddItem(id,"Cal Bonner",1);
AddItem(id,"Annie Glide",2);
AddItem(id,"Ethan Bonner",3);
AddItem(id,"Kevin Tucker",4);
AddItem(id,"Lynn Bonner ",5);
AddItem(id,"Jim Bonner",6);
AddItem(id,"Jodie Pulanski",7);
AddItem(id,"Cal & Jane",8);
AddItem(id,"Kevin & Jane",9);
break;
case "dald":AddItem(id,"Rachel Stone",0);
AddItem(id,"Gabe Bonner",1);
AddItem(id,"Edward Stone",2);
AddItem(id,"Kristy Brown",3);
AddItem(id,"Ethan Bonner",4);
AddItem(id,"Jane Darlington ",5);
AddItem(id,"Cal Bonner",6);
AddItem(id,"Gabe & Rachel",7);
AddItem(id,"Ethan & Kristy",8);
break;
case "lbg": AddItem(id,"Lady Emma Wells-Finch ",0);
AddItem(id,"Kenny Traveler",1);
AddItem(id,"Torie Traveller ",2);
AddItem(id,"Ted Baudine ",3);
AddItem(id,"Dexter O'Conner",4);
AddItem(id,"Shelby Traveller",5);
AddItem(id,"Warren Traveller",6);
AddItem(id,"Hugh Duke of Beddington",7);
AddItem(id,"Kenny & Emma",8);
break;
case "fl": AddItem(id,"Nealy Litchfield Case",0);
AddItem(id,"Mat Jorik",1);
AddItem(id,"Lucy Jorik",2);
AddItem(id,"Bertis Wayne",3);
AddItem(id,"Charlie Wayne",4);
AddItem(id,"Jason Williams",5);
AddItem(id,"Toni DeLuca",6);
AddItem(id,"Mat & Nealy",7);
AddItem(id,"Mat & Lucy",8);
break;
default: break;
}
}
// End -->
</script>
I really would appreciate you help, cause I totally stuck right now.
Thanks, Nina