Add custom Javascript in Magento admin form

magento-js
Standard

Magento is flexible enough to insert your custom JavaScript code snippets in forms created by your very own Magento modules & extensions.

$field = $fieldset->addField('title', 'text', array(
    'label' => Mage::helper('module')->__('Title'),
    'name' => 'title',
    'required' => true,
    'class' => 'required-entry input-text',
));
$field->setAfterElementHtml('<script>
//<![CDATA[

// here goes your custom Javascript

//]]>
</script>');

Advertisements

4 thoughts on “Add custom Javascript in Magento admin form

  1. Hi Tahir, I can’t found that method `setAfterElementHtml`
    What is the classname of the `$field` object?

    Thanks about the post. Its short but useful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: