开发者

Get values from html table using codeigniter

开发者 https://www.devze.com 2023-01-11 22:47 出处:网络
How can I get the values from a html table and pass that to a controller in codeigniter? I\'m passing an array to开发者_Python百科 a view. I walk that array and display its content in a table where th

How can I get the values from a html table and pass that to a controller in codeigniter? I'm passing an array to开发者_Python百科 a view. I walk that array and display its content in a table where the user can alter the table. For example, adding a row, or deleting one, but changing values is a possibility too. But then the user saves the data by pressing the button 'save'.

How do i get the data from the table and pass that to php?


When the "save" button is pressed you trigger a javascript function that uses the DOM to get at the values you want. You "select" a table cell and then use innerhtml to get the string inside it. Using unique html id's on your cells will make this easy. Collect all this data in an array and "send" it to your PHP via an Ajax POST request.

That's one way of going about it. Another way is to use Simplehtmldom where you use PHP instead of JS to get your values. This may be easier / more difficult depending on how good your JS is, but the methods are the same. Simplehtmldom uses a syntax that's quite similar to jquery's and in this case you put the load on the server instead of the client.

0

精彩评论

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