Dynamic Elements

Hi Guys

I am trying to do the something similar to http://www.andresvidal.com/labs/relcopy.html

but I need separate ID for each textfield to be used later on. Basically I am going to have texboxes which take a number and have the summation of all number. If we remove textbox it should delete its value from the SUM or if we add new textbox and put some number into it, it should add the value to the SUM

Thank you

Hi Liz

it’s not really clear what is your question :)

Anyway maybe not set an unique id to textboxes but get and sum them by class, e.g. $(’.textbox-with-number’)

Thank you.

What I am going to do is:

The firs textfiled is always there.

Then let say I put a number into it(100.00 for example)

Then add another textfiled and add 100.50 into it

Then add another textfiled and add 50.00 into it

I need to have a label to show the summation of all these which in this case is 250.50

I may keep adding as much as I need so I dont know how many textbox gonna have as these are dynamically created.

Am I clear now?

Thanks

yes)

this would help you ;)

http://viralpatel.net/blogs/2009/07/sum-html-textbox-values-using-jquery-javascript.html

That really helps. I need exactly the same thing but I dont know how many textfiled I am going to have.

Any hint?

Maybe the jqRelcopy extension can help.

I have modified the js-relcopy code.

So you can use the ‘jsAfterClone’ or ‘jsAfterNewId’ property to calc the sum of the inputs and display the sum.

or you can calculate when focus is out from any textbox:

$(’.textbox’).blur(function () {

var sum = 0;


$('.textbox').each(function() {


    sum += Number($(this).val());


});

});​​​​​​​​​

where this code should be put in a YII app? somewhere in the view?

Thanks

Best example is a computer manufacture company like apple.

Let say apple is going to ship some computers and apple charges by the weight of each.

A customer orders 5 computers so apple has to create 5 records on the invoice the sum the total weight.

Another customer orders 3 computers. The same procedure but for 3 computers

The invoice may include other fields such as customer name, address, Tax rate for shipping address,…

The rest is done, the only part left is the dynamic part