Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Multiple dropdown value feature #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions views/dropdown.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
<option value="2">Option 2</option>
</select>
</div>

<div class="example">
<h3>Multiple value Dropdown List</h3>
<select id="dropdown1" multiple="true">
<option value="" disabled="disabled" selected="selected"
>Please select an option</option
>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
</div>


<script>
var dropdown = document.getElementById('dropdown');
dropdown.onchange = function(event) {
Expand All @@ -20,3 +35,16 @@
.setAttribute('selected', 'selected');
};
</script>

<script>
var dropdown = document.getElementById('dropdown1');
dropdown.onchange = function(event) {
var options = dropdown.getElementsByTagName('option');
for (var i = 0; i < options.length; i++) {
options[i].removeAttribute('selected');
}
document
.querySelector(`#dropdown1 option[value='${event.target.value}']`)
.setAttribute('selected', 'selected');
};
</script>