Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Undefined javascript variable in custom script (sorry the server hiccuped while I posted the first one, please remove if need be)
 
clew
Jr. Member
 
Total Posts:  4
Joined:  2009-04-14
 

Hi,

I am adding a custom script to the page.xml layout file by using:

<action method="addJs"><script>my_dir/my_script.js</script></action>

Inside of my_script.js I have a variable which tries to get updated via a function, but it seems as though the variable is unknown to the function.

For something like this:

var someVar = ‘someVar’;
function foo() {
alert(someVar);
someVar = ‘someOtherVar’;
}

.. when a link on my page runs the function foo(), the alert box pops up and it says, “undefined”

Why is this happening, and how can I resolve this issue?  I noticed that if I just hardcode the usual <script language="JavaScript\" type="text/javascript\" src="my_dir/my_script.js"></script> into the head section of the page, then it works properly.  I’d like to just use Magento’s “addJs” protocol.

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top