Correct
Correct
fetch('save_answer.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
console.error('Save failed');
}
// Update answered indicator immediately
const questionLink = document.querySelector(`a[href="?subject=<?=
$current_subject ?>&q=<?= $current_q ?>"]`);
if (questionLink) {
questionLink.classList.add('answered');
}
})
.catch(error => console.error('Error:', error));
});
});
```
3. Updated save_answer.php:
```php
<?php
include 'config.php';
// Save answer
$_SESSION['answers'][$data['subject']][(int)$data['question']] =
$data['answer'];
The questions are now numbered both in the main display and in the navigation bar.
Answered questions will immediately show with a green indicator in the question
navigation bar.