Yii Framework Forum: how to multiply to fields in javascript+yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to multiply to fields in javascript+yii

#1 User is offline   vidhi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-November 11

Posted 10 March 2012 - 05:45 AM

please can anyone give me the detail description on how to multiply the value of two fields and get its output automatically in the third field.
For example:
I have Quantity, Cost and Amount fields:
if i enter 2 -> Quantity
15000 -> Cost
then i should get the output 30,000 in amount.

please do reply me.
0

#2 User is offline   waitforit 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 415
  • Joined: 09-February 11

Posted 10 March 2012 - 09:55 AM

Are you doing this in an html table or a gridview?

If in a gridview, you want to use the $data property.

For example, if you have columns A and B and want a calculated column C..

Instead of just listing columns like in the example, do this:

array(
'header'=>'Total Quantity',
'value'=>'$data->ColumnA * $data->ColumnB'
),


If just an html table its similar. Lets say you lookup a bunch of stuff with a findAll() call in your model.

In your view, do this:

foreach ($results as $result):
//echo table stuff
//for the <td> cell with the result you want:
<?php echo $result->columnA * $result->columnB; ?>
...

0

#3 User is offline   vidhi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-November 11

Posted 12 March 2012 - 01:25 AM

Thanx sir. Sorry but i forgot to clear that i want the product of quantity and cost in the amount field while filling up the form.

That is, as soon as i type the value in quantity and cost i should automatically get the product of it in amount field.
I hope u got my question now.
Please do send me the proper code for it.

Please please do reply me, and help me out to solve this problem. Im new to yii.

Thanx. :)
0

#4 User is offline   Ravi_Hirani 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 27-February 13

Posted 23 April 2013 - 06:38 AM

i used Jappendo extension.

i have following fields. itemname, quantity, price and amount.

i want to autofill textbox amout for calculating (quantity * price).

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users