How can I delete a row from a table which it has been created with a delete button before?
I need to add an event to btnDeleteOther to delete the current row selected.
I would also need to know how to change id for each textbox created, and populate the value of the textbox with the variable coming to the function(but I guess I would have to ask that in other question).
Code example:
<html>
<head>
<script type="text/javascript">
function createNewRow (text1,text2){
$(document).ready(function(){
$('#tblOtherParties > tbody').append('<tr><td>
<input type="text" id="title1" value=""/>
</td><td>
<input type="text" id="title2"/>
</td><td>
<input type="button" id="btnDeleteOther" value="X"/>
</td></tr>');
});
}
</script>
</head>
<body>
<table style="float:left" id="tblOtherParties">
<thead>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>
<input type="button" id="btnAddOther" title="Add" value="Add" onclick="javascript:createNewRow();"/>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" id="title1"/>
</td>
<td>
<input type="text" id="title2"/>
</td>
<td>
<input type="button" id="btnDeleteOther" value="X"/>
</td>
</tr>
</tbody>
</table>
</body>
</html>
You have issues beyond just getting your row deleted.
This:
would be better written as:
and as for the
clean that up with
Then use the jQuery to act the behavior you wish
EDIT: HUGE assumption on my part is you might want to pass text to the inputs when you add a row as you have the (text1,text2) in there…
To do that, you need a source of those, then you can do that with this: