); echo__("Error-login") correla...">

Write php inside javascript alert

I am writing PHP inside JS as follows

alert(<?php echo __("Error-login") ?>); 

echo__("Error-login") correlates with xml to translate into two languages ​​with symfony, but now it does not work.

How to fix it?

+2
source share
4 answers

You are missing quotes in the alert() call.

 alert('<?php echo __("Error-login") ?>'); 
+4
source

Your string will be

 alert(Error-login); 

As you can see, you are missing quotation marks:

 alert('Error-login'); 

If someone uses quotation marks in the translation, this will also result in an error:

 alert('Error are here'); 

Thus, you need to avoid single quotes before passing them to Javascript.

+2
source

try it

 <?php echo '<script language="javascript">confirm("Do you want this?")</script>;'; ?> 
+1
source

You must specify the file as. Php. Since JavaScript does not support php code as inside.

 [javatpoints ][1] 
+1
source

Source: https://habr.com/ru/post/1434228/


All Articles