Add custom Javascript in Magento admin form

Add custom Javascript in Magento admin form

In previous post we learnt how to render custom html in tabs block. Now lets add custom JavaScript in Magento admin form. Magento is flexible enough to insert your custom JavaScript code snippets in forms created by your very own Magento modules & extensions.

You can put setAfterElementHtml method right after addField as shown below.

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

// here goes your custom Javascript

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

Author: Tahir Yasin

Tahir is a Passionate Web Developer from Lahore, Pakistan and a guy with NEVER-STOP-LEARNING attitude who keeps an eye on emerging technologies and customer trends.

1 thought on “Add custom Javascript in Magento admin form”

Leave a Reply

Your email address will not be published. Required fields are marked *