dhtmlxToolbar with dinamically populated listbutton

Hi again,

I have created a toolbar with the users of a mysql database, the code is:

<?
$counteruser=1;
$status=0;
$result = mysql_query("SELECT * FROM tbluser ORDER BY Status, UserID", $link);
while ($users=mysql_fetch_array($result)){

	if($status<>$users["Status"]){
		echo 'this.addListOption("Userlist","xx",' . $counteruser . ', "separator");'; 
		$counteruser++; 
		$status=$users["Status"];
	}
	
	echo 'this.addListOption("Userlist", "' . $users["UserID"] . '", ' . $counteruser . ', "button", "' . $users["Collaboratore"] . '");';

	$counteruser++;
}
?>

The problem now is that i’m not able to append the action, what I want to do is simple; If a user is selected the page should load the page with his data (ex. user.php?UID=1).

You’ll need to use the onClick event of the toolbar, of course, but the problem is knowing what the relevant IDs are for the buttons that are the users. For this I recommend appending some unique text at the beginning of the $users[“UserID”] that you can test for to identify them, and then strip it off to pass the UserID. Something like this (I added “user” to the beginning of the button ID, but use something that makes sense and is unique enough to stand out):

echo 'this.addListOption("Userlist", user"' . $users["UserID"] . '", ' . $counteruser . ', "button", "' . $users["Collaboratore"] . '");';

Event code:

toolbar.attachEvent("onClick",function(id){
    if (id.indexOf("user") === 0){
        var url = "/path/to./user.php?UID=" + id.replace("user","");
        // Load data from url, just showing above how to extract the UserID from the button id.
    }
}

Perfect, it was a really good suggestion:

myToolbar.attachEvent("onClick", function(id){
	<?
	$result = mysql_query("SELECT * FROM tbluser ORDER BY Status, UserID", $link);
	while ($users=mysql_fetch_array($result)){
			echo 'if(id=="User' . $users["UserID"] . '"){location.replace("home.php?UID=' . $users["UserID"] . '");}';
	}
	?>
	if(id=="home"){location.replace("home.php?m=6");}

with one while loop I append the buttons on the list and with the second loop I append the onclick event. So I can add also the events that are not on connection with users.