Trying to get row data alert. Why am I getting multiple alerts on click?
<p>I am at early stages of learning js and jquery. I am stuck in a problem I dont understand.
I have a HTML form where I am collecting user inputs. When submit button is clicked the user input is saved as a new row to a table (Lets call it "myTable"). I got that part done. But now I want to get the row data when I click on a row in myTable. I kind of have that too. I do get the data when clicking on the row, Except when I click on the row I get the same data in alert multiple times. The first time I click on the row I get one alert, the second time two... and so on. Please point out my error.Here is my html:</p>

<pre><code>&lt;div&gt;label&gt;First Name: &lt;/label&gt;
&lt;input id="firstname" type="text" name="first name"/&gt;

&lt;br&gt;
&lt;label&gt;Last Name: &lt;/label&gt;
&lt;input id="lastname" type="text" name="last name"/&gt;

&lt;input type ="button" value = "Submit" onclick ="addRow()" &gt;
&lt;/div&gt;

&lt;table id="myTable" border=1 onclick="load_row()"&gt;
        &lt;tr &gt;
            &lt;td&gt;
            First Name
            &lt;/td&gt;
            &lt;td&gt;
            Last Name
            &lt;/td&gt;
        &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>And here is my javascript:
This function adds the user input as new row to the table:</p>

<pre><code>var addRow = function(){
var firstname = document.getElementById("firstname").value;
var lastname = document.getElementById("lastname").value;


$("#myTable tr:last").after("&lt;tr&gt;&lt;td&gt;" + firstname + "&lt;/td&gt;&lt;td&gt;" + lastname + "&lt;/td&gt;&lt;/tr&gt;" );   
};
</code></pre>

<p>And this function is alerting with the details of the row I click on. This is where I guess I'm doing something wrong:</p>

<pre><code>var load_row = function(){
var rows = $("#myTable tr");

rows.click(function() {
    var data = new Array();
    var cells = $(this).find("td");
    cells.each(function(i, cell) {
        data.push($(cell).text());
    });
    alert(data);
});

};
</code></pre>
