We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Javascript Calculations on Channel Entry Data

Development and Programming

areichert's avatar
areichert
13 posts
13 years ago
areichert's avatar areichert

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.

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

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,

       
areichert's avatar
areichert
13 posts
13 years ago
areichert's avatar areichert

Thanks, Bhashkar.

I did find this add-on after sending my request, so I was going to just try this: http://devot-ee.com/add-ons/cp-css-js

Let me know if you think this add-on is not preferred for any reason.

       
areichert's avatar
areichert
13 posts
13 years ago
areichert's avatar areichert

One other question, I want a javascript function to happen during an event (e.g. onChange of the field in the CP), but this would require changing the CP code. Is that possible, or is there another way?

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi Areichert,

I didn’t use the extension “CP CSS & JS”. In this used hook is “cp_js_end” so I think, you can put your JS with the help of this extension.

Best Regards,

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.