Radio Buttons:  

CPT 106 · Franklin College · Erich Prisner · 2002-2006

HTML

Radio buttons are indicated by stand-alone input tags with attributes type="radio" and a name, like inname="gender". They also can (and must, if you submit this to a PHP page) have a value attribute, like in value="female". Note that radio buttons that belong to a group where only one is supposed to be clicked must have the same name. The word "checked" without quotation marks inside the tag (which is also an attribute) would indicate that this option is checked by defauly, like in <input type="radio" name="gender" value="female" checked > You can also use the XML compatible writing checked="checked".

JavaScript

If the form name is "Form1", then an array with name window.document.Form1.gender is created in JavaScript. The length of the array is the number of radio buttons of the same name. The elements have the property "checked". window.document.Form1.gender[0].checked is true if the first radio button is checked, otherwise it would be false, and so on.

PHP

The php-page where the data is send to obtains a variable whose name is the name of the radio button with a $ in front of it, like in $gender. The value of that variable is the value of the selected button; in the example $gender=="female" would be true.


Erich Prisner, November 2006