jQuery UI dialogs based on dynamically generated information
<p>Right now I have a table with a few items, each of which has an Edit icon. When the edit icon is clicked, the corresponding database ID of the item (its name) is sent via a $.get() AJAX method to process.php, which generates a JQuery UI dialog consisting of a few of that database item's attributes. </p>

<p>The first item that I click on brings up the proper dialog box with all of the attributes filled in the text boxes. However, when I click a different item, the same dialog box appears with the first item's information. Any other ones I click on still have that first item's information in the dialog box. </p>

<p>What I'm guessing is happening is that the data sent back to index.php, the new div and the jquery dialog call, has already been echo'd through and appended to the page--thus I get the same first box over and over. I just can't figure out how to fix it. </p>

<p>portion of index.php:</p>

<pre><code>        $('#edit_link').live('click', function(e){
            var ID = $(this).attr('name');
            console.log(ID);
            $.get('process.php', {taskID: ID}, function(data){
                $('body').append(data);
            });
            e.preventDefault();
        })
</code></pre>

<p>...the console successfully logs each item's taskID, so that's not the problem.</p>

<p>process.php:</p>

<pre><code>if(isset($_GET['taskID'])){
    $taskID = $_GET['taskID'];
    $task = TaskDB::getTask($taskID);
    $duration = $task-&gt;getDuration();
    $description = $task-&gt;getDescription();
    $deadline = $task-&gt;getDeadline();
    echo '&lt;script&gt;$("#dialog").dialog({
                    height: 150,
                    width: 300,
                    modal: true,
                    buttons: {
                        "Save Task": function() {
                            $( this ).dialog( "close" );
                        },
                        Cancel: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });&lt;/script&gt;&lt;div id="dialog" title="Edit Task" style="display:none;"&gt;
        &lt;p&gt;Deadline: &lt;input type="text" style="margin-right:10px;" value="'.$deadline.'"/&gt; Duration (hours): &lt;input type="text" style="width:20px;" value="'.$duration.'"/&gt;&lt;/p&gt;
        &lt;p&gt;Description: &lt;input type="text" style="width: 200px;" value="'.$description.'"/&gt;&lt;/p&gt;
    &lt;/div&gt;';

}
</code></pre>

<p>The echo portion is where I think the problem is, as the previous echoed data is not cleared out if another Edit was clicked. </p>

<p>Any help would be greatly appreciated. Also, I'm not entirely sure if what I'm doing is the best means for carrying out this goal (having PHP generate so much html/javascript), so any suggestions regarding that would also be very much appreciated. Thanks!</p>
