<html>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript'>
<?php
// this sets variables sot session for nodeid
$nid = 1;//$_GET["nnid"];
session_start();
$_SESSION['sesnodid']=$nid;
?>
var array;
$(document).ready(function (){
$('#itemsOnPageDiv input:checkbox').click(function(event){
var obj = [];
$('#itemsOnPageDiv input[type=checkbox]:checked').each(function(index, value){
obj.push($(this).attr("value"));
alert($(this).attr("value")+" added to array");
});
array = JSON.stringify(obj);
});
});
$(document).ready(function(){
$("#cl").click(function(){
$.post('buildUserPage.php', { array : array },
function(output){
$('#debug').html(output).show();
});
alert(array);
});
});
</script>
<div id="itemsOnPageDiv">
<?php
include("hawkfunctions.php");
newPageCheckBoxBuider();
$user_page_cell_info = getUserPageCellInfo($nid);
$i = 0;
echo "<script>";
while($i < count($user_page_cell_info)){
echo "
alert('Clicking ".$user_page_cell_info[$i]['tag_id']."');
\$(document).ready(function(){
\$('#".trim($user_page_cell_info[$i]['tag_id'])."').trigger('click');
});";
$i++;
}
echo "</script>";
?>
</div>
<button id="cl">Save</button>
<div id = 'debug'></div>
</html>
OK. I have a list of checkboxes built from an sql db. I use php to write jquery that gets the correct 'checked' boxes based on data in the db. I then have this script 'click' the needed checkboxes. Each 'click' is then to populate an array. This array will contain the data needed from the jquery 'clicked' boxes and any boxes checked or unchecked by the user. This array is to be used by another php script to change the db based on the changes in what boxes are checked.
Here is the problem:
The boxes that are supposed to be checked correctly get checked but. The array that is supposed to get populated doesn't get correctly populated all the time. Most noticeably the array is empty if only one of the check boxes is initially checked. The user unchecking then checking again seems to fix this but obviously this isn't ideal. Sometimes when 2 are checked one of the checkboxes data doesn't enter the array. Any amount past this seems OK.