How check box values can be accessed in the form processing scripts?

Suppose that you were asked to create a way for a large eCommerce web site to ascertain the interests of its visitors. You might want to know what product lines customers are interested in. Rather than asking the user to type into a text box what product lines they are interested in, it would make more sense to use a series of check boxes to limit the choices to those that makes sense for your business.


Further, check boxes are useful if there is a group of related yes/no type questions that are not mutually exclusive. That is, there are a number of yes/no types questions, and the user should be able to answer each question in the affirmative or negative.

For the user interests’ example, you might ask the users to choose what product lines they are interested in. You then might list several product lines such as Home Electronics, Major Appliances, and Stereos. It would be nice to have a series of check boxes next to each product line name, so that the user could check the product lines that interest them. In this example, we’d have three check boxes, one for each of the three product lines.

Check boxes are created with the<input> tag. For a check box, you need to set the TYPE property to TYPE=CHECKBOX. The NAME property is slightly different for check box. Rather than having a unique NAME for each check box, you can group check boxes by giving them all the same NAME. In the product line examples, you would want to give all three check boxes the same NAME. The VALUE property needs to be unique among check boxes that have the same NAME. The VALUE property is what the form processing script will receive when referring to check box group.

Let’s write some HTML to create a form to query users about their interests in the three product lines. The code will create three check boxes. When creating a check box, the <INPUT> tag only creates the check box. You need to use HTML to label the check box.

<HTML>
<BODY>
<FORM METHOD=POST ACTION=”/scripts/somefile. asp”>
What product lines are you Interested in? <BR>
<INPUT TYPE= CHECKBOX NAME= “Product Line” VALUE=”HOME Electronics”>
Home Electronics
<BR>
<INPUT TYPE= CHECKBOX NAME= “Product Line” VALUE=”Major Appliances”>
Major appliances
<INPUT TYPE=CHECKBOX NAME=”Product Line” VALUE=”Stereos”>
Stereos
<p>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

It can create three check boxes. Recall that checkboxes are created using the <INPUT>tag with TYPE property set to CHECKBOX. IN 5, 8, AND 11 we create our three related checkboxes, each with the same NAME.

Each check box in the group of related checkboxes will be uniquely identified in the form processing script via the INPUT tag’s VALUE property.


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.