javascript - Add & Subtract TR on Button Click (ID +1) -



javascript - Add & Subtract TR on Button Click (ID +1) -

hey i'm looking have table of products order form.

i user able add together & subtract rows (adding & removing products w/ qty & remarks.)

i have pieced , works few exceptions.

i need id of each input +1 while val('') on new inputs/row. the subtract button works removes lastly & row. removing & add together button it.

could show me examples of how +1 inputs & have subtract button show on 2nd row? or lead me in right direction? in advance-

html:

<table id="mytable" width="250px" border="0" cellspacing="0" cellpadding="0" style="text-align:center;> <thead> <tr class="product"> <th style="text-align:center;"><strong>item</strong></th> <th style="text-align:center;"><strong>qty.</strong></th> <th style="text-align:center;"><strong>remarks</strong></th> </tr> </thead> <tr name="product" class="product"> <td width="100px" style="padding-left:7px; padding-right:7px;"><input type="text" width="100px" name="product" id="product" /></td> <td width="5px" style="text-align:center; padding-left:7px; padding-right:7px;"><input type="text"maxlength="2" name="qty" id="qty"></td> <td width="100px" style="padding-left:7px; padding-right:7px;"><input type="text" name="remarks" id="remarks" /></td> <td><input type="submit" name="add" id="add" value="+" style="width:20px; text-align:center;"/></td> <td><input type="submit" class="subtract" value="-" style="width:20px; text-align:center; display:none;"/></td> </tr> </table>

what i'm using now:

$("#add").click(function() { $('#mytable tbody>tr:last').clone(true).insertafter('#mytable tbody>tr:last'); $('#mytable tbody>tr:last #product').val(''); $('#mytable tbody>tr:last #qty').val(''); $('#mytable tbody>tr:last #remarks').val(''); $('#mytable tbody>tr:last #add').val('+'); $("input.subtract").click(function() { $(this).closest("tr").remove(); });

instead of cloning, create new tr id equal $('#mytable tbody>tr: last') id value + 1 , append table. delete tr specific id, utilize function parameter. in function delete specific tr. (<input type="button" class="subtract" value="-" style="width:20px; text-align:center; display:none;" onclick="remove({id});"/>)

javascript jquery html

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -