Browse Source

finilization 09-forms

09-forms
senne 4 years ago
parent
commit
0e07f7cdbd
2 changed files with 15 additions and 2 deletions
  1. 1
    1
      09-forms/index.html
  2. 14
    1
      09-forms/scripts/main.js

+ 1
- 1
09-forms/index.html View File

@@ -67,7 +67,7 @@
</label>
<label>
selectfield
<select name="select" >
<select multiple name="select" >
<option value="select-1">select1</option>
<option value="select-2">select2</option>
<option value="select-3">select3</option>

+ 14
- 1
09-forms/scripts/main.js View File

@@ -3,4 +3,17 @@ const form = document.getElementById('form');
form.addEventListener('submit', function(event){
event.preventDefault();
console.log(event);
})

const selectedOptions = form.querySelectorAll('option:checked');
for(let i = 0; i < selectedOptions.length;i++){
console.log(selectedOptions[i].value);
}

const radioButton = form.querySelector('input[name=radio]:checked');
console.log(radioButton.value);

const checkOptions = form.querySelectorAll('input[name=checkbox]:checked');
for(let i = 0; i < checkOptions.length;i++){
console.log(checkOptions[i].value);
}
})

Loading…
Cancel
Save