Push Values to Multi Select
I need to push values which i am getting from database to multi select.Below code will push data to text area based on onchange in select.I need to change text area to multi select.How to achieve this? Calling below method like
HTML
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "");
document.getElementById("object_custom_name").value = result;
}
}
);
}
javascript ruby-on-rails ajax
add a comment |
I need to push values which i am getting from database to multi select.Below code will push data to text area based on onchange in select.I need to change text area to multi select.How to achieve this? Calling below method like
HTML
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "");
document.getElementById("object_custom_name").value = result;
}
}
);
}
javascript ruby-on-rails ajax
What is in the ajax result? Is it an array? Can you show the result?
– mridula
Jan 1 at 10:33
Yes. ,Device-1,Device -2, Device-3
– Raja1983
Jan 1 at 10:46
@Raja1983 can you please send me sample response so that I can give you an accurate answer.
– wasipeer
Jan 1 at 11:28
yes.result is ,Device.10001.Enable ,Device.WiFi.AccessPoint.101 ,Device.WiFi.AccessPoint.101.Security
– Raja1983
Jan 1 at 11:51
add a comment |
I need to push values which i am getting from database to multi select.Below code will push data to text area based on onchange in select.I need to change text area to multi select.How to achieve this? Calling below method like
HTML
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "");
document.getElementById("object_custom_name").value = result;
}
}
);
}
javascript ruby-on-rails ajax
I need to push values which i am getting from database to multi select.Below code will push data to text area based on onchange in select.I need to change text area to multi select.How to achieve this? Calling below method like
HTML
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "");
document.getElementById("object_custom_name").value = result;
}
}
);
}
javascript ruby-on-rails ajax
javascript ruby-on-rails ajax
asked Jan 1 at 10:28
Raja1983Raja1983
237
237
What is in the ajax result? Is it an array? Can you show the result?
– mridula
Jan 1 at 10:33
Yes. ,Device-1,Device -2, Device-3
– Raja1983
Jan 1 at 10:46
@Raja1983 can you please send me sample response so that I can give you an accurate answer.
– wasipeer
Jan 1 at 11:28
yes.result is ,Device.10001.Enable ,Device.WiFi.AccessPoint.101 ,Device.WiFi.AccessPoint.101.Security
– Raja1983
Jan 1 at 11:51
add a comment |
What is in the ajax result? Is it an array? Can you show the result?
– mridula
Jan 1 at 10:33
Yes. ,Device-1,Device -2, Device-3
– Raja1983
Jan 1 at 10:46
@Raja1983 can you please send me sample response so that I can give you an accurate answer.
– wasipeer
Jan 1 at 11:28
yes.result is ,Device.10001.Enable ,Device.WiFi.AccessPoint.101 ,Device.WiFi.AccessPoint.101.Security
– Raja1983
Jan 1 at 11:51
What is in the ajax result? Is it an array? Can you show the result?
– mridula
Jan 1 at 10:33
What is in the ajax result? Is it an array? Can you show the result?
– mridula
Jan 1 at 10:33
Yes. ,Device-1,Device -2, Device-3
– Raja1983
Jan 1 at 10:46
Yes. ,Device-1,Device -2, Device-3
– Raja1983
Jan 1 at 10:46
@Raja1983 can you please send me sample response so that I can give you an accurate answer.
– wasipeer
Jan 1 at 11:28
@Raja1983 can you please send me sample response so that I can give you an accurate answer.
– wasipeer
Jan 1 at 11:28
yes.result is ,Device.10001.Enable ,Device.WiFi.AccessPoint.101 ,Device.WiFi.AccessPoint.101.Security
– Raja1983
Jan 1 at 11:51
yes.result is ,Device.10001.Enable ,Device.WiFi.AccessPoint.101 ,Device.WiFi.AccessPoint.101.Security
– Raja1983
Jan 1 at 11:51
add a comment |
2 Answers
2
active
oldest
votes
You simply have to replace text area with the multi-select and append the value in that multi-select.
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
<select id='multi-select' ...>
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "").split(',');
var arrayLength = result.length;
for (var i = 0; i < arrayLength; i++) {
var option = document.createElement("option");
option.text = result[i];
option.value = result[i];
var select = document.getElementById("multi-select");
select.appendChild(option);
}
}
}
);
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
|
show 9 more comments
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
// result in array
result = result.replace(/\/g, "");
referenceNode = document.getElementById("object_custom_name");
//document.getElementById("object_custom_name").value = result;
var myDiv = document.getElementById("myDiv");
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < result.length; i++) {
var option = document.createElement("option");
option.value = result[i];
option.text = result[i];
selectList.appendChild(option);
}
referenceNode.parentNode.insertBefore(myDiv, referenceNode.nextSibling);
}
}
getting array is not defined
– Raja1983
Jan 1 at 11:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994721%2fpush-values-to-multi-select%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You simply have to replace text area with the multi-select and append the value in that multi-select.
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
<select id='multi-select' ...>
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "").split(',');
var arrayLength = result.length;
for (var i = 0; i < arrayLength; i++) {
var option = document.createElement("option");
option.text = result[i];
option.value = result[i];
var select = document.getElementById("multi-select");
select.appendChild(option);
}
}
}
);
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
|
show 9 more comments
You simply have to replace text area with the multi-select and append the value in that multi-select.
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
<select id='multi-select' ...>
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "").split(',');
var arrayLength = result.length;
for (var i = 0; i < arrayLength; i++) {
var option = document.createElement("option");
option.text = result[i];
option.value = result[i];
var select = document.getElementById("multi-select");
select.appendChild(option);
}
}
}
);
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
|
show 9 more comments
You simply have to replace text area with the multi-select and append the value in that multi-select.
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
<select id='multi-select' ...>
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "").split(',');
var arrayLength = result.length;
for (var i = 0; i < arrayLength; i++) {
var option = document.createElement("option");
option.text = result[i];
option.value = result[i];
var select = document.getElementById("multi-select");
select.appendChild(option);
}
}
}
);
You simply have to replace text area with the multi-select and append the value in that multi-select.
<select id="select-execution-group-update" class="form-control" onchange="getParamListForCustomGroupUpdate()">
<select id='multi-select' ...>
//JS file
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
result = result.replace(/\/g, "").split(',');
var arrayLength = result.length;
for (var i = 0; i < arrayLength; i++) {
var option = document.createElement("option");
option.text = result[i];
option.value = result[i];
var select = document.getElementById("multi-select");
select.appendChild(option);
}
}
}
);
edited Jan 1 at 11:57
answered Jan 1 at 11:00
wasipeerwasipeer
704717
704717
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
|
show 9 more comments
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
It is coming as single option.,device1,device 2,device 3.
– Raja1983
Jan 1 at 11:14
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 you can try now.
– wasipeer
Jan 1 at 11:30
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
@Raja1983 and please accept the answer if it works now.
– wasipeer
Jan 1 at 11:31
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
Thanks.Getting error-Uncaught TypeError: Cannot read property 'appendChild' of null
– Raja1983
Jan 1 at 11:35
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
I found an issue.It is coming.But coming as single letters
– Raja1983
Jan 1 at 11:37
|
show 9 more comments
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
// result in array
result = result.replace(/\/g, "");
referenceNode = document.getElementById("object_custom_name");
//document.getElementById("object_custom_name").value = result;
var myDiv = document.getElementById("myDiv");
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < result.length; i++) {
var option = document.createElement("option");
option.value = result[i];
option.text = result[i];
selectList.appendChild(option);
}
referenceNode.parentNode.insertBefore(myDiv, referenceNode.nextSibling);
}
}
getting array is not defined
– Raja1983
Jan 1 at 11:30
add a comment |
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
// result in array
result = result.replace(/\/g, "");
referenceNode = document.getElementById("object_custom_name");
//document.getElementById("object_custom_name").value = result;
var myDiv = document.getElementById("myDiv");
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < result.length; i++) {
var option = document.createElement("option");
option.value = result[i];
option.text = result[i];
selectList.appendChild(option);
}
referenceNode.parentNode.insertBefore(myDiv, referenceNode.nextSibling);
}
}
getting array is not defined
– Raja1983
Jan 1 at 11:30
add a comment |
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
// result in array
result = result.replace(/\/g, "");
referenceNode = document.getElementById("object_custom_name");
//document.getElementById("object_custom_name").value = result;
var myDiv = document.getElementById("myDiv");
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < result.length; i++) {
var option = document.createElement("option");
option.value = result[i];
option.text = result[i];
selectList.appendChild(option);
}
referenceNode.parentNode.insertBefore(myDiv, referenceNode.nextSibling);
}
}
function getParamListForCustomGroupUpdate() {
var selected_execution_group = document.getElementById("select-execution-group-update").value;
$.ajax({
method: "GET",
dataType: "text",
url: "getObjectList",
data: {
execution_group_name: selected_execution_group
},
success: function (result) {
// result in array
result = result.replace(/\/g, "");
referenceNode = document.getElementById("object_custom_name");
//document.getElementById("object_custom_name").value = result;
var myDiv = document.getElementById("myDiv");
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < result.length; i++) {
var option = document.createElement("option");
option.value = result[i];
option.text = result[i];
selectList.appendChild(option);
}
referenceNode.parentNode.insertBefore(myDiv, referenceNode.nextSibling);
}
}
edited Jan 1 at 11:55
answered Jan 1 at 10:58
VishalVishal
3,2793932
3,2793932
getting array is not defined
– Raja1983
Jan 1 at 11:30
add a comment |
getting array is not defined
– Raja1983
Jan 1 at 11:30
getting array is not defined
– Raja1983
Jan 1 at 11:30
getting array is not defined
– Raja1983
Jan 1 at 11:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994721%2fpush-values-to-multi-select%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is in the ajax result? Is it an array? Can you show the result?
– mridula
Jan 1 at 10:33
Yes. ,Device-1,Device -2, Device-3
– Raja1983
Jan 1 at 10:46
@Raja1983 can you please send me sample response so that I can give you an accurate answer.
– wasipeer
Jan 1 at 11:28
yes.result is ,Device.10001.Enable ,Device.WiFi.AccessPoint.101 ,Device.WiFi.AccessPoint.101.Security
– Raja1983
Jan 1 at 11:51