create a page with a name and date field in javascript

To create a page with a name and date field, you can follow these steps:

  1. Create an HTML form with two input fields for name and date:
<form>
  <label for="name">Name:</label>
  <input type="text" id="name" name="name"><br>

  <label for="date">Date:</label>
  <input type="date" id="date" name="date"><br>
</form>
180 chars
8 lines
  1. Add some CSS to style your form:
form {
  border: 1px solid #ccc;
  padding: 10px;
  width: 300px;
}

label {
  display: inline-block;
  width: 100px;
  margin-bottom: 10px;
}

input[type="text"],
input[type="date"] {
  padding: 5px;
  width: 200px;
  border-radius: 3px;
  border: 1px solid #ccc;
  margin-bottom: 10px;
}
290 chars
21 lines
  1. Use JavaScript to grab the values from the form and do something with them:
index.tsx
const form = document.querySelector('form');
const nameInput = document.querySelector('#name');
const dateInput = document.querySelector('#date');

form.addEventListener('submit', (event) => {
  event.preventDefault(); // Prevent the form from submitting normally
  
  const name = nameInput.value;
  const date = dateInput.value;
  
  // Do something with the name and date
  console.log(`Name: ${name}\nDate: ${date}`);
});
426 chars
14 lines

This will create a form with a name and date field and use JavaScript to grab the values when the form is submitted.

gistlibby LogSnag