在javascript文件中转义<?php ...?>

I'm busy doing server side and client side validation for magento. this validation works fine on server side (php)

on the client side i am using javasrcript.

When i started on this. i had my javascript embedded on a phtml file and everything was working as expected.

because i am using magento so I decided to inject the javascript file via page.xml

When I added the javascript code instead of getting the message pulled I get the php as is.

Here is my javascript:

function DefaultAddressErrorChangeNotAllowedMessage() {
    alert("<?php echo Mage::helper('invent_general')->getDefaultAddressErrorChangeNotAllowedMessage();?>");
    return;
}

I run this when a user hit the onclick it will point to this function DefaultAddressErrorChangeNotAllowedMessage() and the

 <?php echo Mage::helper('invent_general')->getDefaultAddressErrorChangeNotAllowedMessage();?>

will be populated as is.

but when I embed this directly to a phtml file it pull the correct message.

I there a way for javasrcipt that I can use to escape the php and get the correct message which is pulled from config.xml

PHP is rendered server side only. If you need to "inject" PHP specific values to your javascript, then you either need to render the actual value as part of the output of the php script, or you need to take a new roundtrip to the server, using Ajax.

Javascript is clientside, PHP is server side, so all php has been evaluated when javascript is loaded. This means, you can alert php echos, but you can't run PHP operations or any PHP logic in Javascript. You need ajax for this.

sorry for my clumsy answer, but maybe you lost the simple things. I see that your javascript contains php tag, so i think you should insert your javascript code into .php extension because .js extension can't recognise the php tag.