Jump to content

Newbie Question: Dynamic Toggle Buttons


bst3ck

Recommended Posts

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)

SampleList.png

 

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.