I want to display an alert box showing a message with PHP.
Here is my PHP code:
<?php
header("Location:form.php");
echo '<script language="javascript">';
echo 'alert(message successfully sent)'; //not showing an alert box.
echo '</script>';
exit;
?>
But it is not working.
This question is related to
php
javascript
html
alert
There is a syntax error (typo):
It's alert
not alery
.
change your output from
echo '<script language="javascript>';
to
echo '<script type="text/javascript">';
you forgot double quotes... and use the type tag
echo '<script language="javascript>';
Seems like a simple typo. You're missing a double-quote.
echo '<script language="javascript">';
This should do.
When I just run this as a page
<?php
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
exit;
it works fine.
What version of PHP are you running?
Could you try echoing something else after: $testObject->split_for_sms($Chat);
Maybe it doesn't get to that part of the code? You could also try these with the other function calls to check where your program stops/is getting to.
Hope you get a bit further with this.
echo "<script>alert('same message');</script>";
This may help.
I don't know about php but i belive the problem is from this :
echo '<script language="javascript>';
echo 'alery("message successfully sent")';
echo '</script>';
Try to change this with :
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
Try this:
Define a funciton:
<?php
function phpAlert($msg) {
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}
?>
Call it like this:
<?php phpAlert( "Hello world!\\n\\nPHP has got an Alert Box" ); ?>
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
Source: Stackoverflow.com