Validation and get multiple selected values from HTML listbox javascript

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 7

  • @kolosafogaming1502
    @kolosafogaming1502 3 роки тому

    Thanks, exactly what I wanted

  • @alexoiik
    @alexoiik 3 роки тому

    Thanks for the help!!! it worked :)

  • @incognitopenpal07
    @incognitopenpal07 2 роки тому

    How we can add a add button to ListBox which gets the values from another js program to fill in list box

  • @riddhokumar1724
    @riddhokumar1724 2 роки тому

    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.

  • @silvanusmarie7645
    @silvanusmarie7645 3 роки тому +1

    how this works without submit?

  • @YaskShelat
    @YaskShelat 4 роки тому +2

    Do you have this code on git or somehwere?

    • @stergiostziahanas6532
      @stergiostziahanas6532 4 роки тому +2

      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