How to insert multi select drop down data value into sql table(in one field) Pls find below attached images from my project. pls assist me
-
2You need to share the code in the question itself, not as an image. You have written the code, what's issue you are facing with the code? – Chetan Jun 26 '20 at 20:40
-
how do you planning to store these in single table..or do you have another table to store mutiselct field? – Always_a_learner Jun 27 '20 at 10:58
4 Answers
You can convert users input values into a string/ Json string & save that. Example-
"["Oracle", "Bayan", "SAP"]"

- 94
- 4
Use javascript function with an onchange event on the select box where you can amend the selected value to a comma seperated string. Save this string in your db.
While retrieving it, change the string to an array and loop over the options to check the selected values.

- 14
- 5
-
can you share sample code to me. so it is easy for me to understand about it – Joyal George Jun 27 '20 at 05:33
It looks like you're building a many-to-many
data structure. You should not store the 'many' features directly in your 'projects' table. You should have a ProjectId
in your projects table, and a FeatureId
in your features table, and then a 'ProjectFeature' table for the many-to-many with 'FeatureId' and 'ProjectId'.
If you use an ORM like Entity Framework, and model your data structures correctly, you will get model classes in your project that let you query Project.Features
and get back an enumerable of features.

- 4,916
- 2
- 20
- 37
your JS function:
function getMultipleSelectedValue(a){
var comma1=", ";
var man12="";
var man11="";
for (var i1 = 0; i1 < a.options.length; i1++) {
if(a.options[i1].selected){
var man1=a.options[i1].value;
var xz1=man1.trim();
if(xz1!=""){
man11=man11+man1+comma1;");
}}}
man11 = man11.replace(/,\\s*$/, \"\");
document.getElementById('hiddenfiled').value=man11; //here i am saving the value in a hidden field
}
your select field (note that I am using servlets that's why there is an out.println
String[] arrayOfString2 = rectohexcolorsnames.split("\\s*,\\s*");//split your comma separated string into an array
out.println("<select title=\"Rien de Sélectionné\" multiple required data-live-search=\"true\" data-live-search-style=\"startsWith\" class=\"selectpicker\" id=\"rectohex\" name=\"rectohex\" onchange=\"getMultipleSelectedValue(this)\">");
while (resultSet7.next()) {
String str16 = resultSet7.getString(1).trim();
String str18 = "";
boolean bool = false;
for (int b = 0; b < arrayOfString2.length; b++) {
String str17 = arrayOfString2[b].trim();
if (str16.equals(str17)) {
str18 = str16.replace("_", " ").trim();
out.println("<option value=\"" + str16 + "\" selected>" + str18 + "</option>");
bool = true;
}
}
if (!bool) {
str18 = str16.replace("_", " ").trim();
out.println("<option value=\"" + str16 + "\" >" + str18 + "</option>");
}
}
out.println("</select>");

- 14
- 5