开发者

Saving data from a dynamic html table using javascript

I load data from a mysql table into a HTML table. Then the user can add or remove one or more rows. Finally I have to save the changes into the database. All this have to be done using PHP and javascript.

I know this does not seem very hard. In fact, I managed to load data from database into the HTML table and add or remove rows from it, using javascript function but I'm having the hardest time trying to save changes from the table. How can I delete an specific row from the table, considering that these rows don't have id's since they are dynamically added? How can I access data from an specific开发者_JS百科 row?

I hope you guys can help me out. This is driving me nuts! Thank you and sorry for my English.


If you are adding them dynamically can't you give the rows id's? Or maybe iterate through the table with javascript?

var theTable = document.getElementById("theTableId");
for (var i=0, row; row=table.rows[i]; i++) {
          // Remove if deleted
}


If you are not developing for mobile or embedded platforms, you may want to considering leverage some well-developed libraries, such as DataTables and jEditable.

There is an example from DataTables, which uses jEditable to allow inline editing for the table. That might be something close to what you want.

The DataTables library allows your source to be from a number of different places, e.g. DOM, AJAX, JavaScript arrays or server-side. Have a look at the examples on their website.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜