Hello I have a form that allows the user to check as many options as they like and then hit submit. Is there any way to have the input type 'checkbox' submit more than one value?
For example right now I have:
<input type="checkbox" value="testuser">
But I want something like:
<input type="checkbox" value="testuser" valuetwo="1">
Is there any way to achieve this second option? Thanks!
Since there is no way to submit to values, is there a way to submit them both in value one? For example:
<input type="checkbox" value="testuser,1">
And if so how would I separate the value into two?
Checkbox is used to make a choice between two options. Input from each checkbox is made to a single variable. A checkbox can pass one of the two values to this variable - one value for the checked state and another one for the unchecked state.
Checkboxes are objects of a HTML form which behaves like a toggle switch. i.e, a checkbox can be in one of the two states, either checked or unchecked. From a group of checkboxs user can select multiple options.
The simplest way to create a checkbox in HTML is by using the input tag. We have set the input type to “checkbox” as you can see in the example code. The name attribute lets us give a name to the checkbox, and with the value attribute, we specify the value it holds.
From your comments, it sounds like you have some JavaScript that handles the data before it's submitted. If that's the case, you can add a data attribute to the checkbox. To use your example, you could call it data-valuetwo
.
<input type="checkbox" value="testuser" data-valuetwo="1">
Then, your JavaScript can use getAttribute
to retrieve the value in your data-valuetwo
attribute and handle it appropriately. It could look something like this:
var valuetwo = checkbox.getAttribute("data-valuetwo");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With