HuyPV
Monday, December 27, 2010
<?php
$arrCheckedCat = isset($_POST['cat']) ? $_POST['cat'] : array();
$submittedPage = isset($_POST['p']) ? intval($_POST['p']) : 1;
if ($submittedPage < 1) $submittedPage = 1;
$submittedT = isset($_POST['t']) ? $_POST['t'] : '';
?>
<form name="frmF" action="" method="post">
<input type="text" name="t" value="<?php echo $submittedT ?>" />
<input type="hidden" name="p" value="<?php echo $submittedPage ?>" />
Cat 1 <input value="1" type="checkbox" name="cat[]" <?php echo in_array(1, $arrCheckedCat) ? 'checked' : '' ?> />
Cat 2 <input value="2" type="checkbox" name="cat[]" <?php echo in_array(2, $arrCheckedCat) ? 'checked' : '' ?> />
Cat 3 <input value="3" type="checkbox" name="cat[]" <?php echo in_array(3, $arrCheckedCat) ? 'checked' : '' ?> />
<input type=submit value="Submit">
</form>
<div id="pList" style="border:1px solid red">
<a href="javascript:void(0);" onclick="gotoPage(1)">1</a>
<a href="javascript:void(0);" onclick="gotoPage(2)">2</a>
<a href="javascript:void(0);" onclick="gotoPage(3)">3</a><br />
Paging
<?php var_dump($_POST); ?>
</div>
<script type="text/javascript">
function gotoPage(p) {
var pagingT1Param = '<?php echo $_POST['t']; ?>';
var pagingCatsParam = '<?php echo implode(",", $arrCheckedCat); ?>'.split(',');
// Re-bind current submitted data
var eins = document.getElementsByTagName('input');
var i, nein = eins.length;
for (i = 0; i < nein; i++) {
ein = eins.item(i);
if (ein.type == 'checkbox') {
if (in_array(ein.value, pagingCatsParam)) ein.checked = true;
else ein.checked = false;
}
}
document.frmF.t.value = pagingT1Param;
document.frmF.p.value = p;
document.frmF.submit();
}
function in_array(e, a) {
var i;
for (i in a) {
if (e == a[i]) return true;
}
return false;
}
</script>
Title:
Javascript Paging and submit data
Description:
<?php $arrCheckedCat = isset($_POST['cat']) ? $_POST['cat'] : array(); $submittedPage = isset($_POST['p...
...
Rating:
4