mikeg542 Posted April 15, 2009 Share Posted April 15, 2009 The subject sums it up, I have an ajax/jquery function that creations checkboxes when you click on another set of checkboxes. But for some reason I can't add another layer of the same thing (clicking on the inner checkboxes doing something with ajax) here's my code: Main page: <script type="text/javascript" src="javascript/jquery-1.3.2.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function () { $('.innerchecky').click(function () { alert("yo"); if ($('.innerchecky').is(':checked')) { url = 'test2.php?clickedinner='+$(this).val(); alert(url); $('#outputText'+$(this).val()).load(url); } else { url = 'test2.php'; $('#outputText'+$(this).val()).load(url); } $('.innerchecky').each(function(){ if (!this.checked) { url = 'test2.php'; $('#outputText'+$(this).val()).load(url); } }); } ); $('.checky').click(function () { if ($('.checky').is(':checked')) { url = 'test2.php?clicked='+$(this).val(); $('#outputText'+$(this).val()).load(url); } $('.checky').each(function(){ if (!this.checked) { url = 'test2.php'; $('#outputText'+$(this).val()).load(url); } }); } ); //protect against refreshes that don't empty fields } ); </script> (the alert is a testing thing) And the html/php in the main page: <?php $query = "SELECT id, name from research WHERE active=1"; $rs = dbquery($query); while($row = db_fetch_assoc($rs)) { echo "<input type=checkbox class=checky id=".$row['id']." value=".$row['id'].">".$row['name']."<br />"; $var = "<table cellpadding=4><tr><td> </td><td><div id=outputText".$row['id']."></div></td></tr></table><br />"; echo $var; } ?> And the relevant part of test2.php that is run by ajax include 'php/includes.php'; $clicked = $_GET['clicked']; $clickedinner = $_GET['clickedinner']; $unclicked = $_GET['unclicked']; if(!isset($_SESSION['clickedarray'])) { $arrayl = array(); $_SESSION['clickedarray'] = $arrayl; } if (!empty($clicked)) { $query = "SELECT expertise from expertisecategories WHERE research=".$clicked; $rs = dbquery($query); while($row2 = db_fetch_assoc($rs)) { if (db_num_rows($rs) > 0) { $query1 = "SELECT name,id from expertise WHERE id=".$row2['expertise']; $rs1 = dbquery($query1); while($row = db_fetch_assoc($rs1)) { echo "<input type=checkbox class=innerchecky id=".$row['id']." value=".$row['id'].">".$row['name']."<br />"; } } } } The problem is probably something pretty stupid because I'm not the best with jquery/javascript. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.