在html中的复选框上提交多个值和隐藏值

时间:2021-11-22 09:27:58

Is there a way to submit multiple form fields by tying it to one checkbox eg:

有没有办法通过将多个表单字段绑定到一个复选框来提交多个表单字段,例如:

<input type=hidden name=code value="cycle_code" />

<input type=checkbox name=vehicle value="cycle" />

<input type=hidden name=code value="car_code" />

<input type=checkbox name=vehicle value="car" />

I want to be able to check car and get car_code submitted also. and same for cycle

我希望能够检查汽车并获得car_code。和周期相同

2 个解决方案

#1


0  

You could use javascript to dynamically set the value of the hidden field.

您可以使用javascript动态设置隐藏字段的值。

#2


0  

The HttpServletRequest maps parameters like so: Map<String,String[]>

HttpServletRequest映射参数如下:Map ,string>

HTML form fields values are stored as a String array. If there's only one value, it is just an array of one String. In your case, you should have an array that looks something like this:

HTML表单字段值存储为String数组。如果只有一个值,则它只是一个String的数组。在您的情况下,您应该有一个类似于下面的数组:

String[] param = request.getParameter("code");
param[0] => "cycle_code"
param[1] => "car_code"

#1


0  

You could use javascript to dynamically set the value of the hidden field.

您可以使用javascript动态设置隐藏字段的值。

#2


0  

The HttpServletRequest maps parameters like so: Map<String,String[]>

HttpServletRequest映射参数如下:Map ,string>

HTML form fields values are stored as a String array. If there's only one value, it is just an array of one String. In your case, you should have an array that looks something like this:

HTML表单字段值存储为String数组。如果只有一个值,则它只是一个String的数组。在您的情况下,您应该有一个类似于下面的数组:

String[] param = request.getParameter("code");
param[0] => "cycle_code"
param[1] => "car_code"