1

I have a little problem to add an external javascript function in a <select>.

I've got a file form.php in /app/code/local/{my_namespace}/{my_module}/Block/Adminhtml/{my_entity}/edit/tab/form.php

I've got another file in js/{my_module}/verifForm.js

In my form.php, there is one select field where I put a : 'onchange' => 'myfunction()'

And myfunction() appear in verifForm.js At the moment, it's just an alert('hello') in it, just to try.

But it doesn't work, when I change the select, my console says : Uncaught ReferenceError: myfunction is not defined

So there is my question, how can I call this external function with my onchange ?

skynetch
1,6724 gold badges20 silver badges30 bronze badges
asked May 30, 2016 at 15:59

1 Answer 1

2

You need to use your module layout xml, local.xml or other layout to add your custom javascript to the page header

eg

<yourpackage_yourmodule_yourcontroller_action translate="label" module="yourpackage_yourmodule"> 
 <reference name="head">
 <action method="addJs">
 <script>{my_module}/verifForm.js</script>
 </action>
 </reference>
</yourpackage_yourmodule_yourcontroller_action>

See Layout for Magento module

answered May 30, 2016 at 18:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.