1 | initial version |
There are multiple ways to submit multiple values in a single HTML form. The most common methods are:
<form action="/submit" method="post">
<input type="text" name="name" value="John">
<input type="text" name="age" value="30">
<input type="email" name="email" value="john@example.com">
<input type="submit" value="Submit">
</form>
In this example, we have three input elements with different names and values. When the form is submitted, the server will receive three parameters: name, age, and email.
<form action="/submit" method="post">
<select name="languages[]" multiple>
<option value="HTML">HTML</option>
<option value="CSS">CSS</option>
<option value="JavaScript">JavaScript</option>
</select>
<input type="submit" value="Submit">
</form>
In this example, we have a select element with the name "languages[]" and the multiple attribute. This allows the user to select multiple options. When the form is submitted, the server will receive an array parameter named "languages[]" with the selected options.
<form action="/submit" method="post">
<input type="checkbox" name="colors[]" value="red"> Red<br>
<input type="checkbox" name="colors[]" value="green"> Green<br>
<input type="checkbox" name="colors[]" value="blue"> Blue<br>
<input type="submit" value="Submit">
</form>
In this example, we have three checkboxes with the same name "colors[]" and different values. This allows the user to select multiple options. When the form is submitted, the server will receive an array parameter named "colors[]" with the selected options.
Note: The actual process of submitting multiple values in a single HTML form depends on the server-side language and framework you are using.