[thelist] request JS help for quiz
Kristof Neirynck
k.neirynck at belgacom.net
Mon Jul 22 09:06:02 CDT 2002
I don't quite see why you'd write it that way
this is how I do it
Kristof
<script type="text/javascript">
//f = name of form
//n = name of group
function getValue(f,n)
{
var g = document.forms[f].elements[n];
var retval = 'error - none checked';//value of the checker
radoibutton
var retnr = -1;//number of the checked radiobutton
for (var i = 0; i<g.length; i++)
{
if (g[i].checked)
{
retval = g[i].value;
retnr = i;
}
}
//return retval;//choose what you want returned (in your case
the number)
return retnr;
}
</script>
<form name="quizform"
onsubmit="alert(getValue('quizform','question_01'));return false;">
What's the number?<br />
<input type='radio' name='question_01' value='one' />1<br />
<input type='radio' name='question_01' value='two' />2<br />
<input type='radio' name='question_01' value='three' />3<br />
<input type='radio' name='question_01' value='four' />4<br />
<input type='submit' value=' - Submit - '>
</form>
Sharon F. Malone wrote:
>Dear List:
>
>I'm not so hot at Javascript and am trying to get a quiz to work using it. Keep getting this error. Wondered if someone could help?
>
>This is the error message Netscape generates from the console:
>
>JavaScript Error: [unknown origin]:
>
>missing ; before statement.
>
>line 34 char 18
>.....^
>
>JavaScript Error:
>file:/E|/Sharon/Cheftrain/html/QuizExperiment.html, line 34:
>
>ButtonGroup has no properties.
>
>This is the error message EditPlus generates:
>
>l. 34 char 18 'length' is null or not an object
>Code: 0
>
>
>This is the code:
>
> function GetSelectedButton(ButtonGroup)
>{
> for (var x=0;x<ButtonGroup.length;x++)
> if (ButtonGroup[x].checked) return x
> return 0
>}
>
>It generates the error at the "x" to the left of <ButtonGroup.length;x++)
>
>Best,
>Sharon
>---------------------------------------------------------------------------
>Sharon F. Malone
>"web design and Internet writing services"
>http://www.24caratdesign.com
>sfmalo at 24caratdesign.com
>
>
More information about the thelist
mailing list