I write PHP inside JS in the following way
alert(<?php echo __("Error-login") ?>);
echo__("Error-login") correlates with an xml to translate in two languages with symfony, but now it does not work.
How do I fix this?
sarnold
105k23 gold badges187 silver badges243 bronze badges
3 Answers 3
You are missing quotes in the alert() call.
alert('<?php echo __("Error-login") ?>');
answered Mar 9, 2012 at 9:48
code_burgar
12.3k4 gold badges37 silver badges53 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Your line becomes
alert(Error-login);
As you can see, you are missing the quotes:
alert('Error-login');
If somebody uses quotes in the translation, this will also generate an error:
alert('Error's are here');
So you need to escape single quotes before you pass it to Javascript.
answered Mar 9, 2012 at 9:49
Sjoerd
75.9k16 gold badges140 silver badges180 bronze badges
1 Comment
Simon
it does not work the same alert('<?php echo __("Error-login"); ?>')
try this
<?php echo '<script language="javascript">confirm("Do you want this?")</script>;'; ?>
answered Mar 9, 2012 at 9:51
rejo
3,3405 gold badges29 silver badges35 bronze badges
Comments
default
;in'<?php echo __("Error-login"); ?>'