jquery に問題があります。SQL データベースから配列で結果を取得しています。アイテムは にありtable tr td
ます。各行には一意の ID が保持されます。
しかし、合計を実行するか、1 つのテキスト ボックスに対して onkeyup を実行すると、すべての合計も変化します。
onKeyUp
のイベントを予定していQty
ます。
例えば。:
数量 = 3
ベッドラグ = 20
合計 (予想) = 60
スクリーンショットは次のとおりです。
私のjQueryコードは間違っていますか?
jQuery(document).ready(function(){
var j = 0;
/* COMPUTATION new item */
jQuery('input[id=new_quan_'+j+']').keyup(function(){
j++;
var new_sum = parseInt($('input[id=new_quan_'+j+']').val(), 10);
new_sum *= parseInt($('input[id=new_amt_'+j+']').val(), 10);
jQuery('input[id=new_total_'+j+']').val(new_sum);
});
});
HTML と PHP コードは次のとおりです。
<table cellpadding="5" cellspacing="0" width="100%" id="computation_table">
<tbody>
<tr>
<th>Categories</th>
<th>Qty</th>
<th>Omschrijving</th>
<th>Bedrag</th>
<th>Totaal</th>
<th>BTW</th>
<th></th>
</tr>
<?
$quo_com = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE user_code = '".$_GET['uc']."' and footnote = 'new' and active='1' " ) or die ( mysql_error() );
$get_btw = mysql_fetch_array( $quo_com );
if ( $get_btw['currency'] == 'euro' ) {
$msg_tot = '€';
} elseif ( $get_btw['currency'] == 'usd' ) {
$msg_tot = '$';
}
$sqlview = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE user_code = '".$_GET['uc']."' and footnote = 'new' and active='1' " ) or die ( mysql_error() );
$j = 0;
while( $row = mysql_fetch_array( $sqlview ) ) {
?>
<tr>
<td>
<input type="hidden" name="id_<?=$j?>" value="<?=$row['q_id'];?>" />
<input type="hidden" name="counter" value="<?=$j?>" />
<input type="text" name="category_<?=$j?>" class="text_com" value="<?=$row['category'];?>" />
</td>
<td>
<input type="text" name="quantity_<?=$j?>" id="new_quan_<?=$j?>" class="text_com" value="<?=$row['quo_quantity'];?>" /> x
</td>
<td width="200">
<input type="text" name="quo_definition_<?=$j?>" class="input" value="<?=$row['quo_definition'];?>" />
</td>
<td>
<input type="text" name="quo_amt_<?=$j?>" id="new_amt_<?=$j?>" class="text_com" value="<?=$row['quo_amt'];?>" />
</td>
<td id="total">
<input type="text" name="quo_total_<?=$j?>" id="new_total_<?=$j?>" class="text_com" value="<?=$row['quo_total'];?>" />
</td>
<td>
<input type="text" name="quo_btw_<?=$j?>" class="text_com" value="<?=$row['quo_btw'];?>" />
</td>
</tr>
<?
$j++;
}
?>
</tbody>
</table>
</div>
<br />
<!-- END OF COMPUTATION UPDATE -->
<input type="submit" name="up_item_list" value="Werk de vorm" /> - <input type="submit" name="new_save_list" value="Opslaan nieuw item" /> - <a href="">Annuleren</a>
</form>