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.
use this code
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
The problem was:
- you missed
"
- It should be
alert
notalery
Answer:
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" ); ?>
Answer:
There is a syntax error (typo):
It’s alert
not alery
.
Answer:
echo '<script language="javascript>';
Seems like a simple typo. You’re missing a double-quote.
echo '<script language="javascript">';
This should do.
Answer:
change your output from
echo '<script language="javascript>';
to
echo '<script type="text/javascript">';
you forgot double quotes… and use the type tag
Answer:
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
Answer:
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.
Answer:
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>';
Answer:
echo "<script>alert('same message');</script>";
This may help.
Tags: java, php, phpjavascript