bst3ck Posted August 31, 2011 Share Posted August 31, 2011 Hi Everyone, Please forgive my newbie questions. I am making the long await switch from a .net world to a PHP AJAX world. In my thirst to jump ahead of my skill level, I have hit a issue that I could not find any answers for in the various beginner help manuals. I would like to dynamically create some toggle buttons using MySQL as the source for the values of the toggle. I have been able to populate the list using my PHP file, but I am unable to attached the onClick handler to the elements once they have loaded. (See attached image: SampleList.png for a sample) I was able to test that the onClick function by commenting out the post AJAX call. (See attached image: ToggleButton.png for a sample of what the different states render as with the CSS) Any Suggestions on what I am missing? I am sure I am overlooking something obvious, but I am so new at this that I am not even sure where to start. Thanks BDS <html> <head> <title>My Jira Projects Reporting System</title> <link href="mystyles.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $.post( 'ajaxcalls.php', {} , function(NavList){ $('#Projects').html(NavList).show(); }); $('#Projects a#button').click(function(){ $(this).toggleClass("down"); }); }); </script> </head> <body> <div id="Projects"> //This is a sample to see what it would look like without the ajax post call. <a id="button" title="button">Press Me</a> </div> </body> </html> Here is my PHP code: <?php //Set up connection to the MySQL database mysql_connect("MySQLDB","password") or die(mysql_error()); mysql_select_db("JiraDB") or die(mysql_error()); //Look up Navigation items for this page $sql = mysql_query("SELECT * FROM NavList WHERE PHPPage = 'MainPage' ORDER BY NavOrder"); $NavList = "<strong>JIRA Summary Options</strong><br>"; while($row = mysql_fetch_array($sql)) { $NavText = $row["NavText"]; $NavID = $row["NavId"]; // $NavList .= "<a id='" . $NavId . "' title='" . $NavID . "'>" . $NavText . "</a>"; $NavList .= "<a id='button' title='button'>" . $NavText . "</a>"; } echo $NavList ; ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246085-newbie-question-dynamic-toggle-buttons/ 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.