Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="utf-8" />
- </head>
- <form name="selectForm">
- <p>
- <label for="musicTypes">Wybierz ulubione gatunki muzyki: </label>
- <select id="musicTypes" name="musicTypes" multiple="multiple">
- <option selected="selected">Rege</option>
- <option>Jazz</option>
- <option>Blues</option>
- <option>New Age</option>
- <option>Classical</option>
- <option>Opera</option>
- </select>
- </p>
- <p><input id="btn" type="button" value="Ile gatunków wybrano?" /></p>
- </form>
- <script>
- function howMany(selectObject) {
- var numberSelected = 0;
- for (var i = 0; i < selectObject.options.length; i++) {
- if (selectObject.options[i].selected) {
- numberSelected++;
- }
- }
- return numberSelected;
- }
- var btn = document.getElementById("btn");
- btn.addEventListener("click", function(){
- alert('Ilość zaznaczonych obiektów ' + howMany(document.selectForm.musicTypes))
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement