Creating A Javascript Alert With Php That Has A Php Variable Inside?


Answer :

You only forgot quotations that are required for the JavaScript alert.



If you passed 'hello' to the function, your current code would create alert as:



alert(hello)


instead of doing:



alert("hello")


Therefore, change your line to the following (two double quotes are added before and after concatenating $error):



echo '<script type="text/javascript">alert("'.$error.'");</script>';


and you can use your function:



died('error on whatever');


Display variable php in alert javascript



   <?php 
function died($error) { ?>

<script>alert("<?php echo $error; ?>")</script>

<?php die();
} ?>


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable