Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active January 25, 2024 23:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ziadoz/36f52e02b07a4530e6194bee20c92300 to your computer and use it in GitHub Desktop.
Select Date Dropdown / Input
Link: https://jsbin.com/poyuxuwina/edit?html,console,output
<!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