1

I've added a small bit of prototype js to app/design/adminhtml/default/default/template/catalog/product/edit.phtml

$$("#status").invoke(
    'on', 
     'change',
     function(){
        Form.Element.setValue("status_updated",new Date);
    }
);

When I attempt to load it as an external file the script doesn't work anymore, no 404, no script error.

I've added the following to app/design/adminhtml/default/default/layout/local.xml

<layout version="0.1.0">
    <adminhtml_catalog_product_edit>
        <reference name="head">
            <action method="addJs"><script>js/timestamp_update.js</script></action>
        </reference>
    </adminhtml_catalog_product_edit>
</layout>

If anyone has an idea it would be appreciated.

2 Answers 2

1

Since your js is loaded before DOM, you need to do it like this:

document.observe("dom:loaded", function() {
    $$("#status").invoke(
        'on',
        'change',
        function(){
            Form.Element.setValue("status_updated",new Date);
        }
    );
});
1

Cleaning up the PrototypeJS code

$$("#status").invoke(
     'on', 
     'change',
     function(){
        Form.Element.setValue("status_updated",new Date);
     }
);

can be optimized to

$('status').observe('change',function(){
    $('status_updated').setValue(new Date());
});

on() and observe() can be used interchangeably unless you are observing delegated events, then you need to use on()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.