问题
We have a form that Span Across multiple pages and the form is full of checkboxes and radio-buttons. Requirement is that when a user navigates across multiple pages of the form, the user should be able to see the checkboxes and radio-buttons he has already Selected before the form Submit button is pressed.
I am copying the code segement that is used to generate the Checkboxes in the form - this is a Sample code Only.
<form action="car_model.php" method="post" name="car_form" id="car_form">
$q10 = "SELECT ...
$r10 = mysqli_query ($dbc, $q10);
if (mysqli_num_rows($r10) > 0) {
while ($row10 = mysqli_fetch_array($r10, MYSQLI_ASSOC))
{
echo '<p class="normal_text"><input type="checkbox" name="model_selection[]" value="' . $row10['model_id'] . '" onclick="return KeepCount()"; />' . $row10['car_model_name'] . '</p></br>';
}
}
</form>
if ($pages > 1) {
echo '<br /><p>';
// Determine what page the script is on:
$current_page = ($start/$display) + 1;
// If it's not the first page, make a Previous button:
if ($current_page != 1) {
echo '<a href="car_model.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
}
// Make all the numbered pages:
for ($i = 1; $i <= $pages; $i++) {
if ($i != $current_page) {
echo '<a href="car_model.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}
// If it's not the last page, make a Next button:
if ($current_page != $pages) {
echo '<a href="car_model.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';
}
echo '</p>';
}
I understand that JQuery is a Good tool for this purpose - how to use it?
回答1:
If using server side session variables is not an option then you could implement it in such a way that when you click "next" instead of loading a new page you just hide the current content place holder of the visible part of the form and show the next one at it's place and the same when clicking back.
This can easily be done with jQuery. Here is a very simple example to get you started:
$("#next").click( function () {
$("#page1").hide();
$("#page2").show();
});
$("#back").click( function () {
$("#page1").show();
$("#page2").hide();
});
Fiddle
Good luck!
来源:https://stackoverflow.com/questions/20994395/how-to-remember-checkbox-radio-button-selection-in-a-mulit-page-form