Reputation: 49
How can I javascript alert my php error messages? Here is my code:
<?php echo showmessage($msg)?>
I want to make it into an alert, how can I do that?
Upvotes: 1
Views: 65
Reputation: 1726
?>
<script type="text/javascript">
alert("The error is <?php echo $msg ?>");
history.back();
</script>
<?php
Or
echo '<script language="javascript">';
echo 'alert(Message here)';
echo '</script>';
Upvotes: 1
Reputation: 43728
The use of json_encode
makes sure that characters that needs to be escaped are escaped.
<script>
alert(<?php echo json_encode($msg); ?>);
</script>
Upvotes: 1