Assigning numerical values to radio buttons
I'm trying to put together a simple quiz script. Well, simple to those who know what they are doing perhaps.
Each question has 3 options worth 0, 1, 10 points respectively. I'm using radio buttons like so (html stripped):
input type="radio" name="q1" value="0"
input type="radio" name="q1" value="1"
input type="radio" name="q1" value="10"
input type="radio" name="q2" value="0"
input type="radio" name="q2" value="1"
input type="radio" name="q2" value="10"
etc
At the end I call a function to tally q1+q2+etc (form.score.value = form.q1.value + form.q2.value + etc) and display the score. Unfortunately, The score is always "NaN" which I assume means not a number.
Can you not assign a numeric value to a radio button? Does it have to be converted? Is it a simple syntax issue?
Any ideas on this? I kind of left this part of the project to the end (duh!) and am now butting my head against a deadline.
.....
taff posted this at 20:57 — 11th January 2002.
They have: 956 posts
Joined: Jun 2001
never mind!
figured it out
yabber posted this at 21:12 — 11th January 2002.
They have: 93 posts
Joined: Dec 2001
what was the solution ?
I was wondering the same thing yesterday
Mika
taff posted this at 21:33 — 11th January 2002.
They have: 956 posts
Joined: Jun 2001
2 things actually:
1) multiply each variable by 1 to make it numeric.
2) But then, it still wouldn't work. I suspect that a Radio button's value must be boolean. So I added a hidden field for each question (a1,a2,etc) and assigned the value to it using an onClick event
form.a1.value*1 + form.a2.value*1 + etc
seems to work like a charm.
.....
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.