0

I would make sure that the items in select from activating the specific features I'll explain. I have this select:

<select id='selection'> <!-->this is for the class<!-->
   <option>4B</option>
   <option>5B</option>
</select>

<select id='secondSelection'> <!-->this is for the data to be loaded<!-->
</select>

if I select 4B must load all pupils corresponding to that class, pupils are in the array 4B. if instead go to select 5B must be able to load in the other select the contents of the 5B. The user can also decide to select both classes.

EXAMPLE:

4B [selected in selection] => Mario, Luigi, John are now loaded in secondSelection

similarly for all values ​​have to be able to do the same thing by enabling multiple. I have already made a similar code in the past, but here the situation is a bit 'different, I would like the help of an expert. PEACE!

5
  • 1
    need jQuery solution? Commented Oct 11, 2014 at 14:56
  • no, i use pure javascript no jquery Commented Oct 11, 2014 at 14:56
  • Please post what you have tried and explain specifically where you are stuck. Questions about connected selects have been asked many times already. Commented Oct 11, 2014 at 14:56
  • You have to listen change event on the select Commented Oct 11, 2014 at 14:58
  • have a look at --> w3schools.com/jsref/event_onchange.asp Commented Oct 11, 2014 at 15:00

2 Answers 2

1

Well, you can do

var b4 = ["Mario", "Luigi", "John"],
    b5 = ["Some", "Other", "Names"],
    elem = document.getElementById('selection');
elem.onchange = function () {
    document.getElementById('secondSelection').innerHTML = this[elem.options[this.selectedIndex].text == "4B" ? "b4" : "b5 "].map(function (x) {
        return "<option>" + x "</option>";
    }).join();
};
Sign up to request clarification or add additional context in comments.

Comments

0

You can use

<select onchange="myFunction()">

<script> function myFunction(){ } </script>

it will also work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.