Share this Page URL

Chapter 12. Need Feedback? Create a Form... > Multiple Choice Options: Radio Butto... - Pg. 137

Need Feedback? Create a Form! 137 When you submit a form with a check box, the data returned by the test script is a bit different from the data returned by the other controls. For one thing, the script returns only the values for check boxes that were activated; for another, the value returned for these checked check boxes is "on". For example, in the check- box.htm file, if the check box named "Beards" is activated when the form is submitted, the following line will appear in the results: Beards = on Multiple Choice Options: Radio Buttons Instead of yes/no choices, you might want your readers to have a choice between three or four options. In this case, radio buttons are your best bet. With radio buttons, the user gets two or more options, but they can pick only one at a time. Here's the general format: <INPUT TYPE="RADIO" NAME="Field Name" VALUE="Value"> Field Name is the usual field name, except in this case you supply the same name to all the radio buttons that you want grouped together. (More on this in a sec.) Value is a unique text string that specifies the value of the option when it's selected. In addition, you can also add CHECKED to one of the buttons to have the browser activate the option by default. The following HTML document (radiobtn.htm on this book's CD) puts a few radio buttons through their paces. Webmaster Wisdom In a rare burst of nerd whimsy, the HTML powers-that-be named radio buttons after the old car radio buttons that you had to push to select a station. <HTML> <HEAD> <TITLE>Radio Button Example</TITLE> </HEAD> <BODY> <H3>Survey</H3> <FORM ACTION="" METHOD="POST"> Which of the following best describes your current salary level: <DL><DD> <INPUT TYPE="RADIO" NAME="Salary" VALUE="Poverty" CHECKED>Below the poverty line<BR> <INPUT TYPE="RADIO" NAME="Salary" VALUE="Living">Living wage<BR> <INPUT TYPE="RADIO" NAME="Salary" VALUE="Comfy">Comfy<BR> <INPUT TYPE="RADIO" NAME="Salary" VALUE="DINK">DINK (Double Income, No Kids)<BR> <INPUT TYPE="RADIO" NAME="Salary" VALUE="Rockefellerish">Rockefellerish<BR> </DD></DL> Which of the following best describes your political leanings: <DL><DD> <INPUT TYPE="RADIO" NAME="Politics" VALUE="Way Left" CHECKED>So far left, I'm right<BR> <INPUT TYPE="RADIO" NAME="Politics" VALUE="Yellow Dog">Yellow Dog Democrat<BR> <INPUT TYPE="RADIO" NAME="Politics" VALUE="Middle">Right down the middle<BR>