Here's a complete example of an HTML + JavaScript web page that meets your requirements:
✅ Features
- User enters their email at the top.
- Displays JPG photos from a local directory (simulated via HTML file input).
- Loads item descriptions from a text file (format:
filename.jpg:description).
- Displays each item with photo, description, and checkbox.
- On clicking "Send", generates a
.txt file containing only the selected items' descriptions and triggers download.
📄 Example Input Files
1. items.txt (descriptions):
item1.jpg:Red Chair
item2.jpg:Vintage Lamp
item3.jpg:Wooden Table
**2. Local folder named images/ containing:
item1.jpg
item2.jpg
item3.jpg
💻 Full HTML + JS Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Item Selector</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.item {
display: flex;
align-items: center;
margin-bottom: 20px;
border: 1px solid #ddd;
padding: 10px;
border-radius: 5px;
}
.item img {
max-width: 150px;
margin-right: 20px;
}
.email-container {
margin-bottom: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
}
</style>
</head>
<body>
<div class="email-container">
<label for="email">Enter your email:</label><br>
<input type="email" id="email" placeholder="you@example.com" required>
</div>
<h2>Select Items</h2>
<div id="items-container"></div>
<button onclick="sendSelectedItems()">Send Selected Items</button>
<script>
const itemsContainer = document.getElementById('items-container');
// Load image files and descriptions
function loadItems(imageFiles, descriptions) {
itemsContainer.innerHTML = '';
Array.from(imageFiles).forEach(file => {
const filename = file.name;
const description = descriptions[filename] || 'No description';
const div = document.createElement('div');
div.className = 'item';
const img = document.createElement('img');
img.src = URL.createObjectURL(file);
img.alt = description;
const label = document.createElement('label');
label.style.marginRight = '10px';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.dataset.description = description;
label.appendChild(checkbox);
label.appendChild(document.createTextNode(description));
div.appendChild(img);
div.appendChild(label);
itemsContainer.appendChild(div);
});
}
// Parse description file
function parseDescriptionFile(file) {
const map = {};
const reader = new FileReader();
reader.onload = () => {
const lines = reader.result.split('\n');
lines.forEach(line => {
if (!line.trim()) return;
const [filename, description] = line.trim().split(':');
if (filename && description) {
map[filename] = description;
}
});
const imageInput = document.getElementById('imageInput');
const descriptionInput = document.getElementById('descriptionInput');
loadItems(imageInput.files, map);
};
reader.readAsText(file);
}
// Handle description file upload
function handleDescriptionUpload(event) {
const file = event.target.files[0];
if (file) {
parseDescriptionFile(file);
}
}
// Simulate loading images and descriptions
// You can remove this block if you're embedding directly in server
window.onload = () => {
const imageInput = document.createElement('input');
imageInput.type = 'file';
imageInput.id = 'imageInput';
imageInput.multiple = true;
imageInput.accept = 'image/*';
imageInput.style.display = 'none';
imageInput.onchange = () => {
const descInput = document.getElementById('descriptionInput');
if (descInput.files.length === 0) {
alert('Please upload the description file first.');
return;
}
handleDescriptionUpload({ target: descInput });
};
document.body.appendChild(imageInput);
const descriptionInput = document.createElement('input');
descriptionInput.type = 'file';
descriptionInput.id = 'descriptionInput';
descriptionInput.accept = '.txt';
descriptionInput.onchange = () => {
if (imageInput.files.length === 0) {
alert('Please upload image files first.');
return;
}
handleDescriptionUpload({ target: descriptionInput });
};
descriptionInput.style.marginBottom = '20px';
document.body.insertBefore(descriptionInput, itemsContainer);
};
// Trigger fake image upload to simulate loading local images
function triggerImageUpload() {
document.getElementById('imageInput').click();
}
// Send selected items as a text file
function sendSelectedItems() {
const email = document.getElementById('email').value;
if (!email) {
alert('Please enter your email address.');
return;
}
const checkboxes = itemsContainer.querySelectorAll('input[type="checkbox"]');
let selectedDescriptions = [];
checkboxes.forEach(cb => {
if (cb.checked) {
selectedDescriptions.push(cb.dataset.description);
}
});
if (selectedDescriptions.length === 0) {
alert('Please select at least one item.');
return;
}
const content = selectedDescriptions.join('\n');
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${email}_selected_items.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
</script>
</body>
</html>
🧪 How to Use
- Save the above code as
index.html.
- Open it in a browser.
- Upload the image files (
item1.jpg, etc.) using the hidden file picker (triggered automatically).
- Upload the
items.txt description file.
- Enter your email.
- Select items.
- Click Send Selected Items — downloads a
.txt file with selected item descriptions.
🔒 Notes
- This works entirely client-side — no backend needed.
- If deploying on a server, you could fetch the images and descriptions directly instead of uploading them manually.
- Email is not sent anywhere — it just personalizes the downloaded file name.
Would you like a version that uploads data to a server or sends an actual email?