vendredi 10 novembre 2017

i want to add multiple selection in JS

when i try to select two option it give me the first option two time...
when i try to select two option it give me the first option two time...
when i try to select two option it give me the first option two time...
when i try to select two option it give me the first option two time...
here is the code :

    <head>
        <script type="text/javascript">

            function choices() {
                var y = document.getElementById("s");
                var x = document.getElementById("output");
                var choice = y.value;
    for(i=1;i<=3;i++)
        {
            var current = y[i];
            if(current.selected == true)
                {    x.innerHTML += "the language is, " + choice + "<br>";

                }
        }



            }

        </script>
    </head>

    <body>
        <form action="">
            <fieldset>
                <select id="s" multiple="multiple" size="4">
        <option>--Choose language--</option>
        <option value="HTML">HTML</option>
        <option value="JAVA">JAVA</option>
        <option value="PHP">PHP</option>
        </select>
                <input type="button" value="show" onclick="choices()">
            </fieldset>
        </form>
        <div id="output"></div>

    </body>

    </html>




Aucun commentaire:

Enregistrer un commentaire