I’m working with an application that uses web pages to launch db procedures (as post).
In html code I have:
<select name="key" multiple>
<option value="val1">val1</option>
<option value="val2">val2</option>
...
<option value="valn">valn</option>
When I mark few of them and click submit, following code is send:
key=val1&key=val2&key=val3...
This is caught by db procedure like func(key varchar2). Unfortunatelly procedure catch only the first value.
Is possible in plain html get only one key?
ex. key=val1val2val3
or values separated by something (, ; /)?
Or maybe there is another approach that will allow me to retrieve all the options selected by the user?
I searched a soution but I didn’t find. Also tried to apply js to get a comma separated list but I’m a database base developer not web developer and I couldn’t do it. Apart the fact that on target system js is blockedd.
2
Answers
In plain HTML you can’t use
<select>
tag to select more than one. In case you will need to recreate the<select>
tag using<div>
or some elements like that with JavaScript. Here is an how to do example (https://codeshack.io/multi-select-dropdown-html-javascript/) so you can do It yourself or copy paste it.Just to notify you; while sending
query
like?key1=value1;
you can make splitting yourself like?key1=value1-value2-..;
or?key1=value1,value2,..
and split the query in the other side.You can search on google
HTML multi select dropdown
or if you don’t have too muchoption
tags, you can switch tocheckbox
.Here is an example on checkbox:
This script will stop form submit when clicked to button and get the selected checkboxes and then submit the form with only 1 key.
Example Query:
/submit?options=Option+1,Option+3
You need this, simpler and straight forward. Send this
urlEncodedData
value to server asapplication/x-www-form-urlencoded
content typeOutput value
text=test&key=val1,val2,val3
where key value must be separated by,