[thelist] DOM lvl 0 forms: accessing radio buttons

Peter-Paul Koch gassinaumasis at hotmail.com
Fri Feb 7 08:26:05 CST 2003


>I of course am using the DOM lvl 0 to access forms. Now, I have a
>situation where there may be variations on a radio group. Usually its
>in this order:
>
><input type="radio" value="1" name="CROption"
>onclick="updateCreditReportId();" /> Option 1

Try

<input type="radio" value="1" name="CROption"
onclick="updateCreditReportId(this);" /> Option 1

>BUT - sometimes its REVERSED (the 2nd option is first, with some
>other unrelated changes).

function updateCreditReportId(obj)
   if (obj.checked)
       doSomething;

Now you can see if the radio button the user has clicked on is checked or
not. Usually this is enough information to run a validation/form logic
function.

>Is there another way to get into the radio array? Even this reference
>is in a sense incomplete, since I didn't use elements[], but wasn't
>sure how to do it with the radio array included.

elements[] is not required, though it does make your code easier to read.
Your syntax is perfectly valid.

>I need to essentially be able to reference that one particular radio
>button by name - so no matter what order it ends up in we can check
>it.

See above.

--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
W3C DOM Compatibility Table, expanded & updated
http://www.xs4all.nl/~ppk/js/index.html?version5.html
--------------------------------------------------


_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail




More information about the thelist mailing list