Skip to content

Commit

Permalink
Merge pull request #49 from meet244/main
Browse files Browse the repository at this point in the history
Updated script.js | closes #47
  • Loading branch information
Anshgrover23 authored Oct 12, 2024
2 parents 1b54fc2 + f5ff1cf commit 876c62d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function addTodo() {
inputNameElement.value = '';
inputDateElement.value = '';
inputTimeElement.value = '';
setDefaultDateTime();

// Update the displayed list
updateTodoList();
Expand Down Expand Up @@ -110,5 +111,24 @@ function updateTodo(index) {
updateTodoList();
}

// Initialize the todo list on page load
updateTodoList();
function setDefaultDateTime() {
const inputDateElement = document.querySelector('.js-date-input');
const inputTimeElement = document.querySelector('.js-time-input');

const now = new Date();
const date = now.toISOString().split('T')[0]; // YYYY-MM-DD format
const time = now.toTimeString().split(' ')[0].slice(0, 5); // HH:MM format

inputDateElement.value = date;
inputTimeElement.value = time;
}

// Initialize the todo list and set default date and time on page load
document.addEventListener('DOMContentLoaded', () => {
updateTodoList();
setDefaultDateTime();

// Set focus on the name input field
const inputNameElement = document.querySelector('.js-name-input');
inputNameElement.focus();
});

0 comments on commit 876c62d

Please sign in to comment.