I’m trying to trigger a function in js when clicking on save button in edit product admin page. I followed the suggestions from here: https://magento.stackexchange.com/questions/119542/calling-js-function-when-product-save-button-is-clicked
And I modify in
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php
$this->setChild('save_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('catalog')->__('Save'),
'onclick' => 'productForm.submit(); myFunction();',
'class' => 'save'
))
);
But I don’t know in which template should I put the myFunction(). I tried in
app/design/adminhtml/default/default/template/catalog/product/edit.phtml
and
app/design/adminhtml/default/admintheme/template/catalog/product/edit.phtml
function myFunction(){
console.log('test');
}
but with no success. So my question is: where should I put the function in order to be activated when the save button is clicked?
2
Answers
This got long as a comment, so I’ve added it as an answer:
Conjecture:
Your scoping might be off. Add it to a top-level page like:
index.html
, then you can assign the function as:Since window is a global variable, you should have access to it from your
click
handler!Hypothesis 2
You could actually be putting the function in files that do not import at/before the
click
handler is triggered. (this seems a bit less probable)You can put your code here
appdesignadminhtmldefaultdefaulttemplateindexnotifications.phtml