// ... (previous FamilyMember and FamilyTree code here)
function displayFamilyTreeHTML() {
const container = document.getElementById('family-tree-container');
container.innerHTML = '';
for (let [id, member] of familyTree.members) {
const memberDiv = document.createElement('div');
memberDiv.className = 'family-member';
memberDiv.innerHTML = `
${member.name}
Birth Year: ${member.birthYear}
${member.deathYear ? `Death Year: ${member.deathYear}
` : ''}Parents: ${member.parents.map(p => p.name).join(', ') || 'None'}
Children: ${member.children.map(c => c.name).join(', ') || 'None'}
Spouse: ${member.spouse ? member.spouse.name : 'None'}
`; container.appendChild(memberDiv); } } function addMemberForm() { const form = document.getElementById('add-member-form'); form.innerHTML += ` `; updateMemberSelects(); document.getElementById('new-member-form').addEventListener('submit', function(e) { e.preventDefault(); const name = document.getElementById('name').value; const birthYear = parseInt(document.getElementById('birthYear').value); const deathYear = document.getElementById('deathYear').value ? parseInt(document.getElementById('deathYear').value) : null; const parent1Id = document.getElementById('parent1').value; const parent2Id = document.getElementById('parent2').value; const spouseId = document.getElementById('spouse').value; const newMember = new FamilyMember(familyTree.members.size + 1, name, birthYear, deathYear); familyTree.addMember(newMember); if (parent1Id) newMember.addParent(familyTree.getMember(parseInt(parent1Id))); if (parent2Id) newMember.addParent(familyTree.getMember(parseInt(parent2Id))); if (spouseId) newMember.setSpouse(familyTree.getMember(parseInt(spouseId))); displayFamilyTreeHTML(); updateMemberSelects(); this.reset(); }); } function updateMemberSelects() { const selects = ['parent1', 'parent2', 'spouse']; selects.forEach(selectId => { const select = document.getElementById(selectId); select.innerHTML = ''; for (let [id, member] of familyTree.members) { select.innerHTML += ``; } }); } // Initialize the family tree and display const familyTree = new FamilyTree(); addMemberForm(); displayFamilyTreeHTML();