Checkbox

xiaoxiao2021-03-06  61

Checkbox

1, Checkbox definition

In the JSP or HTML page, CheckBox is often used. For example, this definition:

... < Input type = "checkbox" name = "check_id" size = "6" value = "9">

Submitted We can get all the Checkbox lists selected in the page from the Request object. Take the above definition as an example, if you select the checkbox item of value 1, 2, 5 in the page, you can get the selection:

String [] Checkids = Request.getParameterValues; "Check_ID");

It is possible that some primary web programmers will define this:

... < INPUT TYPE = "CheckBox" name = "check_id9" size = "6" value = "9">

Then, the selection option is obtained when data is taken:

String Checkid1 = Request.getParameterValues; string checkid2 = request.getParameterValues ​​("check_id2"); ... string checkid9 = Request.getParameterValues ​​("check_id9");

This can also solve the problem, but compared, the latter is a dead way, and it is very inconvenient to maintain it, it is not recommended.

2, Checkbox's verification

There is often such a situation, in the page, there is a batch of dynamic checkbox list items and a submitted button, and the business logic needs to be submitted after at least one list item data can be actually submitted. You can use a JavaScript to resolve: Suppose page definitions and related code are as follows: