> On 4/11/06, Mace Eliason <meliason@xxxxxxx> wrote:
> > I am not sure why this won't work I am pretty sure I have done it before;
> >
> > if($error)
> > {
> > echo $errorMessage; // for testing error message is
displayed to screen
> > echo"<script language=\"JavaScript\">alert('$errorMessage');</script>";
> > }
At 11:19 AM 4/11/2006, Anthony Ettinger wrote:
alert('<? echo $errorMessage; ?>');
Or perhaps more effectively:
alert('<?php echo $errorMessage; ?>');
...or to tweak the OP's own syntax, adding curly braces to make sure
PHP is parsing the variable properly:
echo "<script
type=\"text/javascript\">alert('${errorMessage}');</script>";
Mace, what value of $error are you testing? Is the first plain echo
line executing? If it is, I suspect it's the curly braces you've
been missing (although I can't say why; the single-quotes should
provide sufficient delimiters for PHP).
Tangentially, I'd like to mention that if your error message appears
in an alert but nowhere else, then after the user makes the alert go
away (which they might do with an errant keystroke before reading it
properly) the message can't be recalled. I recommend doing for the
user almost exactly what you're doing for debugging purposes --
output the error message to the page AND to a javascript
alert(). The alert() gets their attention, and the page-bound error
message lets them read it again.
if($error)
{
echo <<< hdErrmsg
<div class="error">$errorMessage</div>
<script type="text/javascript">alert('${errorMessage'});</script>
hdErrmsg;
}
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php