C
Claes Andersen
Hi,
I got this piece of code that i intend to use for a quiz program. What it
does is the following. When a user makes a choice in a family of radio
buttons, the other choices are automatically disabled, hence allowing a
"first answer counts" system. It works fine with just one family on a page,
but I need it to work with more ... The function is called from the
respective radio buttons like this:
<input onclick="lockChoice(1,0);" type="radio" name="a1" value="1">
The lockChoice variables (1,0) in the above example are used (or intended to
be so - I do after all have a problem that i need help for;-) to move the
number of the question (1) and the number of the choice (0)
<script language="JavaScript">
function lockChoice(answ,choice){
for (i = 0; i <= 7; i++)
{
if (i != choice)
document.test.a1.disabled = true;
}
</script>
As it is above it is fine, but just for one family of radio buttons. I'm no
shark at JavaScript, but invented the above myself, so at least i got a bit
right ... so here is the big Q:
How do I build the following line:
document.test.a1.disabled = true;
so that it is dynamic also related to answ variable passed from each of the
choices? (a1, a2, a3, a4 etc.)? In short that the above a1 gets a bit
like [answ][a1] or however the syntax should be.
I tried more combinations, but im stuck:-( I'm soon getting my evening
spoiled here, so I address the honorable audience with a hope of a fast
solution. Any suggestions - that lead to the solve of the above - are dearly
appriciated
Best regards,
Claes Andersen
I got this piece of code that i intend to use for a quiz program. What it
does is the following. When a user makes a choice in a family of radio
buttons, the other choices are automatically disabled, hence allowing a
"first answer counts" system. It works fine with just one family on a page,
but I need it to work with more ... The function is called from the
respective radio buttons like this:
<input onclick="lockChoice(1,0);" type="radio" name="a1" value="1">
The lockChoice variables (1,0) in the above example are used (or intended to
be so - I do after all have a problem that i need help for;-) to move the
number of the question (1) and the number of the choice (0)
<script language="JavaScript">
function lockChoice(answ,choice){
for (i = 0; i <= 7; i++)
{
if (i != choice)
document.test.a1.disabled = true;
}
</script>
As it is above it is fine, but just for one family of radio buttons. I'm no
shark at JavaScript, but invented the above myself, so at least i got a bit
right ... so here is the big Q:
How do I build the following line:
document.test.a1.disabled = true;
so that it is dynamic also related to answ variable passed from each of the
choices? (a1, a2, a3, a4 etc.)? In short that the above a1 gets a bit
like [answ][a1] or however the syntax should be.
I tried more combinations, but im stuck:-( I'm soon getting my evening
spoiled here, so I address the honorable audience with a hope of a fast
solution. Any suggestions - that lead to the solve of the above - are dearly
appriciated
Best regards,
Claes Andersen