0

I have an HTML form which posts its information to a java servlet. One of the sections in the HTML is a multiple checkbox where one of the options is an "all of the above" option.

Mode of Transportation:<br>
<input type="checkbox" name="transport" value="Car" /> Car <br>
<input type="checkbox" name="transport" value="Bike" /> Bike <br>
<input type="checkbox" name="transport" value="Public Transit" /> Public Transit <br>
<input type="checkbox" name="transport" value="All of the Above" /> All of the Above <br>

The java page accepts it into an array:

String[] transport = request.getParameterValues("transport");

And now it's supposed to just post back the information: How do I account for the "All of the Above" option? Meaning if it's checked how do I forgo the other checks and list everything?

condit
  • 10,852
  • 2
  • 41
  • 60

2 Answers2

1

Two ways:

Either using javascript, check all the check boxes if All Of the above is selected immediately after select or before posting the form.

Or handle in the server side i.e. before processing, check, if one of the values is All Of the above then handle it appropriately i.e. populate your user answer list with all options provided.

You use statement below to check if All Of the above was selected:

boolean isAllSelected = Arrays.asList(transport).contains("All Of the above");
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
0

Instead of having a value by the name All of the Above

<input type="checkbox" name="transport" value="All of the Above" /> All of the Above <br>

You can use a select all as described here. How to implement "select all" check box in HTML?

Community
  • 1
  • 1
Abhishek kumar
  • 2,586
  • 5
  • 32
  • 38