Calculated field

vaulot

New Member
Hi

I would like to do a very simple thing : compute the product of two fields (called let us say units and price_unit) and put it in a read only field (price_total). I have looked though the forum but could not find a simple step by step answer....

Thanks for the help.
 
Are you wanting to do this with javascript on the form, as they enter / change the units and price, or do you want to do it on the server when the forum is submitted?

If you want to do it in javascript, there have been several threads in the last few months describing how to do that. Try widening your search terms a little ...

Essentially you just add some JS to the onChange event for both the unit and price elements that computes the total cost and assigns it to your read only element. Something like this should work:

Code:
$('fabrik_formdata_X___total').value = $('fabrik_formdata_X__units').value * $('fabrik_formdata_X__price).value;

-- hugh
 
Thanks Hugh for the answer...

In fact I would like to do it on the server once the form is submitted... (I have seen the js answers on the forum but could not find the way to do the change once the form is submitted).
 
Use a form submit script ("as soon as form submitted, simple eval"), and access the $aData[] array directly. To get the array indexes you need, start by just doing this ...

var_dump($aData);

That wil print out the content of $aData, showing you the exact array indexes you'll need (like fabrik_formdata_X___foo). Then get rid of the var_dump, and ...

$aData['total'] = $aData['price'] * $aData['units'];

... or whatever the indexes are you need.

-- hugh
 
Hugh Messenger said:
Use a form submit script ("as soon as form submitted, simple eval"), and access the $aData[] array directly. To get the array indexes you need, start by just doing this ...

var_dump($aData);

That wil print out the content of $aData, showing you the exact array indexes you'll need (like fabrik_formdata_X___foo). Then get rid of the var_dump, and ...

$aData['total'] = $aData['price'] * $aData['units'];

... or whatever the indexes are you need.

-- hugh

I am trying to do a calculation like this also and having problems getting it working...I currently have the following code in the Javascript for the element


$('jos_fabrik_formdata_42__totprice').value = 100;

Where do I put this 'dump' info above?
 
Well the example I was giving was a PHP form submit script on the server side.

See earlier in the thread for a javascript example.

-- hugh
 
Hello,

I try to do the same thing, that is substract the amount in column 1 from the amount in column 2 and display it in column 3.

I used the var_dump($aData); method and it gave me this :

array(22) { ["jos_fabrik_formdata_1___fabrik_internal_id"]=> string(0) "" ["jos_fabrik_formdata_1___dateblocus"]=> string(9) "Semaine 1" ["jos_fabrik_formdata_1___time_date"]=> string(10) "2008-09-18" ["jos_fabrik_formdata_1___nbinscrit"]=> string(1) "0" ["jos_fabrik_formdata_1___nbmax"]=> string(3) "100" ["jos_fabrik_formdata_1___nddisponible"]=> string(0) "" ["tableid"]=> string(1) "1" ["fabrik"]=> string(1) "1" ["task"]=> string(11) "processForm" ["rowid"]=> string(0) "" ["Itemid"]=> string(1) "3" ["option"]=> string(10) "com_fabrik" ["form_id"]=> string(1) "1" ["fabrik_frommodule"]=> string(0) "" ["fabrik__cursor"]=> string(1) "0" ["fabrik__total"]=> string(1) "0" ["returntoform"]=> string(1) "0" ["fabrik_referrer"]=> string(65)

So now, I guess that for my calculation I need to write this :

$aData['nddisponible'] = $aData['nbmax'] - $aData['nbinscrit'];

But where do I put it ? In the formdata_1 ? In another form ? In the result field ?
 
As a form submit script ("As soon as form submitted (simple eval)") on the form you are submitting.

You'll also need to use the full element names for the $aData[] references, like $aData['jos_fabrik_formdata_1___nddisponible'];

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top