I’ve got an application where I’m allowing users to take a spelling test, and they have the option of showing the correct spelling of the word or hiding it. They can toggle this at any time. My problem is that once they start entering in their spellings, if they toggle, it’ll wipe out everything they entered. So somehow I need to capture what they’ve already entered. I’m using a basic onClick that triggers a PHP script.
Here is the toggle:
[code=html]
<select name=”display_spelling” class=”form-control” onClick=”displaySpelling(this.value, <?php echo $result[‘spelling_unit’]; ?>)”>
<option value=”yes” <?php if($result[‘display_spelling’] == ‘yes’) { echo ‘selected’; } ?>>Yes</option>
<option value=”no” <?php if($result[‘display_spelling’] == ‘no’) { echo ‘selected’; } ?>>No</option>
</select>
The PHP script then just receives the spelling test ($result[‘spelling_unit’]) they want to take, runs a query to get those words, then changes the display so the correct spelling either shows or doesn’t show.
Here is the PHP if they want to display the spelling:
[code=php]
$g = 1;
while($g < 50) {
if($y[‘Word’ . $g] != ”) {
echo ‘<div class=”form-group”>’;
echo ‘<label class=”col-sm-3 control-label”>Correct Spelling</label>’;
echo ‘<div class=”col-sm-9″>’;
echo ‘<input type=”text” value=”‘ . $y[‘Word’ . $g] . ‘” class=”form-control” readonly>’;
echo ‘</div>’;
echo ‘<label class=”col-sm-3 control-label”>Student Spelling</label>’;
echo ‘<div class=”col-sm-9″>’;
echo ‘<input type=”text” name=”word’ . $g . ‘”class=”form-control” value=”‘ . $result[‘word’ . $g] . ‘”>’;
echo ‘</div>’;
echo ‘</div>’;
}
$g++;
}
The words are just stored in the DB in columns named Word1, Word2, Word3, etc…, all the way to Word50.
So is there even a way to capture the input fields of word1, word2, etc….?