Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append multiple values to a single parameter in html form?

Tags:

html

jquery

php

Assuming I have the following form:

<form action="process.php">
<input type="checkbox" name="option1" value="oats"> Oats
<input type="checkbox" name="option2" value="beans"> Beans
<input type="hidden" name="parameter" value="a"/>
<input type="submit" value="Submit"/>
</form>

What would normally happen is after clicking on the URL, the browser redirects to:

process.php?option1=oats&option2=beans&parameter=a

How do I make it such that when the submit is clicked all the checkboxes end up as part of the "parameter", but separated by commas? So in other words it would be:

process.php?parameter=a,oats,beans

Best solution with minimal javascript/jquery/html is best if no html solution.

like image 796
Rolando Avatar asked Dec 11 '12 23:12

Rolando


People also ask

How do you add multiple values in HTML?

When present, it specifies that the user is allowed to enter more than one value in the <input> element. Note: The multiple attribute works with the following input types: email, and file. Tip: For <input type="file"> : To select multiple files, hold down the CTRL or SHIFT key while selecting.

Which is the delimited to pass multiple parameters in query type of HTTP GET method?

Parameters are passed to the web application as part of an HTTP request in the form of ”name=value” strings. When multiple parameters are required they are delimited by the '&' character.


1 Answers

If you want several values in one parameter, you have to name it like parameter[]

f.e.:

<form action="process.php">
<input type="checkbox" name="parameter[]" value="oats"> Oats
<input type="checkbox" name="parameter[]" value="beans"> Beans
<input type="hidden" name="parameter[]" value="a"/>
<input type="submit" value="Submit"/>
</form>
like image 173
Pablo Martinez Avatar answered Oct 10 '22 22:10

Pablo Martinez