Question about Jquery and Dynamic form

I used the dynamic form extension of wbagranca. I have a line item and i want to automatically generate total sum in the last field. the js code works as i expected in the 1st form, but on the second form, its not working…can you help me in this? Im a newbie in yii 2.0. Oh my? i cant embed image here?

here is my code




<?php

$script = <<< JS




	$('#tableparticulars-0-particular_title').change(function(){

	var amountId = $(this).val();

	$.get('index.php?r=particulars/amount-particulars',{ amountId : amountId },function(data){

	var data = $.parseJSON(data);

	$('#tableparticulars-0-particular_amount').attr('value',data.particular_amount);

	}); 


	$('#tablecollect-0-particular_quantity').keyup(function() {

        var a = $('#tableparticulars-0-particular_amount').val();

        var b = $(this).val();

        $('#tablecollect-0-particular_total').val((a * <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />.toFixed(2));});});

	

	$('#tableparticulars-1-particular_title').change(function(){

	var amountId = $('#tableparticulars-1-particular_title').val();

	$.get('index.php?r=particulars/amount-particulars',{ amountId : amountId },function(data){

	var data = $.parseJSON(data);

	$('#tableparticulars-1-particular_amount').attr('value',data.particular_amount);}); 


	$('#tablecollect-1-particular_quantity').keyup(function() {

        var aa = $('#tableparticulars-1-particular_amount').val();

        var ba = $(this).val();

        $('#tablecollect-1-particular_total').val((aa * ba).toFixed(2));});})


JS;

$this->registerJs($script);

?>



how can i reuse the code? anyonw?