SammyGh
(Ghazavi)
March 15, 2012, 4:39pm
1
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
vitalets
(Noginsk)
March 15, 2012, 4:51pm
2
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’)
SammyGh
(Ghazavi)
March 15, 2012, 5:11pm
3
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
vitalets
(Noginsk)
March 15, 2012, 5:15pm
4
SammyGh
(Ghazavi)
March 15, 2012, 5:21pm
5
That really helps. I need exactly the same thing but I dont know how many textfiled I am going to have.
Any hint?
joblo
(Joe)
March 15, 2012, 5:50pm
6
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.
vitalets
(Noginsk)
March 15, 2012, 6:51pm
7
or you can calculate when focus is out from any textbox:
$(’.textbox’).blur(function () {
var sum = 0;
$('.textbox').each(function() {
sum += Number($(this).val());
});
});
SammyGh
(Ghazavi)
March 15, 2012, 8:23pm
8
where this code should be put in a YII app? somewhere in the view?
Thanks
SammyGh
(Ghazavi)
March 15, 2012, 8:41pm
9
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