0

I'm using magento 1.9 version.

I am creating custom module, which contains some javascript functions to be included.

I defined all javascript functions in seperate js file and included that js in my xml file under app\design\mytheme\default.

Called the js function in my phtml file. It shows the error : (index):403 Uncaught ReferenceError: myFunction is not defined. How to solve this.

asked Jul 6, 2016 at 9:08
2
  • can you attach XML and JS files here? Commented Jul 6, 2016 at 9:10
  • Sorry i cannot attch my whole XML and JS files due to my company principles. Commented Jul 6, 2016 at 9:26

1 Answer 1

0

there can be several reasons of this issue:

1) Js file is not added to page (if something wrong in your XML)

2) Js file not added in Merged js file (so you can clean JS/Css cache at the bottom of Admin - System - Cache Management page)

3) Js file added, but it's code structure broken.

4) Js file added at the bottom of page, but function called before file insertion

answered Jul 6, 2016 at 9:16
8
  • Thanks for your reply @Neklo. The step 4 is caused my case. Because i called the function On document ready function. But i included the js as normal like <action method="addJs"><script>mymodule/mymodule.js</script></action>. Commented Jul 6, 2016 at 9:23
  • gimme vote up? ^.^ Commented Jul 6, 2016 at 9:26
  • Is there any way to solve this. Commented Jul 6, 2016 at 9:28
  • if <action method="addJs"> code added to <reference name="head"> section - you need to clean JS/Css cache at the bottom of Admin - System - Cache Management page Commented Jul 6, 2016 at 9:29
  • and try to call your function like Event.observe(window, 'load', function() { myFunction(); }); Commented Jul 6, 2016 at 9:30

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.