Last active
January 25, 2024 23:45
-
-
Save ziadoz/36f52e02b07a4530e6194bee20c92300 to your computer and use it in GitHub Desktop.
Select Date Dropdown / Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Link: https://jsbin.com/poyuxuwina/edit?html,console,output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<style> | |
div.date-input:has(input:disabled) { | |
visibility: hidden; | |
} | |
</style> | |
<script> | |
document.addEventListener('DOMContentLoaded', () => { | |
const selectEl = document.querySelector('select[name="relative-date"]'); | |
const dateEl = document.querySelector('input[name="exactdate"]'); | |
dateEl.disabled = true; | |
['load', 'change'].forEach((emit) => { | |
selectEl.addEventListener(emit, (event) => { | |
dateEl.disabled = (event.target.value !== 'Select Date'); | |
}); | |
}); | |
}); | |
</script> | |
<div class="date-dropdown"> | |
<select name="relative-date"> | |
<option selected></option> | |
<option>Today</option> | |
<option>Select Date</option> | |
</select> | |
</div> | |
<hr> | |
<div class="date-input"> | |
<label for="exactdate">Date</label> | |
<input type="date" name="exactdate" id="date" /> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment