New convert form
You're looking to create a new conversion form! That's a great idea. Here's a basic template to get you started:
Conversion Form Template
Form Name: [Insert form name, e.g. "Length Conversion"]
Fields:
- From: [Insert field label, e.g. "Length (inches)"]
- Input type: Text box
- Placeholder text: "Enter length in inches"
- To: [Insert field label, e.g. "Length (centimeters)"]
- Input type: Text box
- Placeholder text: "Enter length in centimeters"
- Convert: [Insert button label, e.g. "Convert"]
- Button type: Submit
Conversion Logic:
- When the user submits the form, retrieve the value from the "From" field.
- Perform the conversion calculation using the following formula:
centimeters = inches * 2.54
- Display the converted value in the "To" field.
Example Code:
HTML:
<form id="length-conversion">
<label>Length (inches):</label>
<input type="text" id="from" placeholder="Enter length in inches">
<label>Length (centimeters):</label>
<input type="text" id="to" readonly>
<button type="submit">Convert</button>
</form>
JavaScript:
const form = document.getElementById('length-conversion');
const fromInput = document.getElementById('from');
const toInput = document.getElementById('to');
form.addEventListener('submit', (e) => {
e.preventDefault();
const inches = parseFloat(fromInput.value);
const centimeters = inches * 2.54;
toInput.value = centimeters.toFixed(2);
});
This is a basic example to get you started. You can customize the form and conversion logic to fit your specific needs.