Bro can you make a some changes of this code? If we added some questions that sel2the right words. Then what exactly the code was. The result shows that your corrected and wrong words. Can you please do this one? It will be very helpful for me if you do this. Thanks in advance.
Get Selected Values How to Validate the Listbox & Get the Selected List Value Using JavaScript
Black Red White Blue Green
style.css --> * { background-color: azure; } app.js --> function listboxresult() { var spanresult = document.getElementById("result"); spanresult.value = ""; var x = document.getElementById("sel"); for (var i = 0; i < x.options.length; i++) { if (x.options[i].selected == true) { spanresult.value += x.options[i].value + " "; document.getElementById("result").innerHTML = spanresult.value; document.getElementById("result").style.color = "green"; } } if (document.getElementById("result").value == "") { document.getElementById("result").innerHTML = " Please Select At least One List Item... ! "; document.getElementById("result").style.color = "red"; } } Info: 1. Click on empty space to show the "Red colored comment" 2. Click on an item to show the "Green colored result" 3. Click using CTRL and/or SHIFT keys for multiple or selected items
Thanks, exactly what I wanted
Thanks for the help!!! it worked :)
How we can add a add button to ListBox which gets the values from another js program to fill in list box
Bro can you make a some changes of this code? If we added some questions that sel2the right words. Then what exactly the code was. The result shows that your corrected and wrong words. Can you please do this one? It will be very helpful for me if you do this. Thanks in advance.
how this works without submit?
Do you have this code on git or somehwere?
index.html -->
Get Selected Values
How to Validate the Listbox & Get the Selected List Value
Using JavaScript
Black
Red
White
Blue
Green
style.css -->
* {
background-color: azure;
}
app.js -->
function listboxresult() {
var spanresult = document.getElementById("result");
spanresult.value = "";
var x = document.getElementById("sel");
for (var i = 0; i < x.options.length; i++) {
if (x.options[i].selected == true) {
spanresult.value += x.options[i].value + " ";
document.getElementById("result").innerHTML = spanresult.value;
document.getElementById("result").style.color = "green";
}
}
if (document.getElementById("result").value == "") {
document.getElementById("result").innerHTML = " Please Select At least One List Item... ! ";
document.getElementById("result").style.color = "red";
}
}
Info:
1. Click on empty space to show the "Red colored comment"
2. Click on an item to show the "Green colored result"
3. Click using CTRL and/or SHIFT keys for multiple or selected items