I’m looking to do javascript calculations on channel entry data and was hoping for some guidance. Ideally, I’d like to be able to enter data into field_a and filed_b and have field_c automatically calculated as their sum. Is the cp_js_end hook the way to go?
Also, I noticed that the fields are numbered in the control panel source code (e.g. field_id_356), instead of using the short name of the field (e.g. member_income). Does this mean that the javascript would have to call each of these fields by this name, or is there a better way to accomplish this?
Thanks in advance.
Hi Areichert,
Yes, you can do it by using the hook “cp_js_end” and can update the field input value.
The field names are being used with field id so it would be better you define these into extension class once and use anywhere into the extension like
<?php
class Your_extension_ext{
private $field1 = 'field_id_1';
private $field2 = 'field_id_2';
private $field3 = 'field_id_3';
function your_function_name(){
/* use like */
$this->$field1;
$this->$field2;
$this->$field3;
}
}
?>Hope this would help you.
Best Regards,
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.