データベースに接続されたHTMLとjQueryを使用して、経費の記録を保持するためのフォームに取り組んでいます..
問題は、「追加」ボタンをクリックすると、新しい列を追加する必要がありますが、代わりにフォームを自動送信することです。
HTML
<form name="myForm" action="mysql_connection.php" method="post">
<table>
<tr>
<td>Expense       
      
      
      
Amount
<br/>
<input type="text" name="expense" id="expense" />
<input type="text" name="amount" id="amount" />
<br/>
</td>
</td>
<td>
<button class="add">Add</button>
</td>
</tr>
</table>
<input type="submit" value="Submit" />
</form>
jQuery
$(document).ready(
function() {
$('button.add').live('click',
function() {
$(this)
.closest('tr')
.clone()
.appendTo('table');
$(this)
.text('Remove')
.removeClass('add')
.addClass('remove');
});
$('button.remove').live('click',
function() {
$(this)
.closest('tr')
.remove();
});
$('input:text').each(
function() {
var thisName = $(this).attr('name'),
thisRrow = $(this)
.closest('tr')
.index();
$(this).attr('name', 'row' + thisRow + thisName);
$(this).attr('id', 'row' + thisRow + thisName);
});
});
ここにフォーム
コードがあります