html - More Rows and More Columns jQuery -
I want a "Add Rows" and "Add Columns" button to the system object. My HTML is:
& lt; Table range = "2" id = "the_table" & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input name = "value_1 []" /> & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; A href = "#" rel = "add_row"> Add line & lt; / A & gt; & Lt; A href = "#" rel = "add_column"> Add column & lt; / A & gt; My jQuery:
$ (document) .ready (function () {var table_id = "#the_table"; jQuery.fn.renderTable = function () {Var rowCount = $ (table_id + 'tr'). Length; var colCount = 0; $ (table_id + 'tr: nth-child (1) td') each (function () {if ($ (this) .attr ('colspan')) {colCount + = + $ (this) .attr ('colspan')}} {colCount ++;}}); if ($ (this [0]). Attr ("rel" ("Name"); id = id.replace (/ value_ (\ d +) /, function (match, number) {} == "add_row") {var id = $ (table_id + "input: last") {Return 'value_' + (parseInt (number, 10) + 1);}); var x = 0; var result = "& lt; tr & gt;"; while (x! = ColCount) {result = & Lt; td & gt; & lt; input name = "'+ + id +'" /> '; x = x + 1;} result + = "& lt; / tr & Gt; Click "; $ (table_id + 'tr: last') (function () ($) () () () (later);} (later (result);} if ($ (this [0]) ("Reliance") == "add_column") {}} $ $ ('a' .renderTable (); Returned;});}); So weird I want to add rows, I want to add a line to it but want to increase the name of the field for php $ _POST ... and add it to a column and increment with the addition column so the name below is 2 x 2 My output for the table will be:
& Lt; Table range = "2" id = "the_table" & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input name = "value_1 []" /> & Lt; / Td> & Lt; Td> & Lt; Input name = "value_1 []" /> & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input name = "value_2 []" /> gt; & Lt; / Td> & Lt; Td> & Lt; Input name = "value_2 []" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; Can this be done? Thank you in advance!! : D
Actually you have to add a new td for each existing one <($ (This [0]). Attr ("rel") == "add_column") {$ (table_id + "tr"), tr : each (function () {var $ this = $ (this), newInput = $ ("& lt; input / & gt;", {name: $ this.find ('td: last input'). Attr ("name")}, NewTD = $ ("& lt; td / & gt;"). Attachment (new input); $ this.append (newTD);}); } See this work!
Comments
Post a Comment