Reputation:
<?php
function alert($msg)
{
echo "<script type='text/javascript'>alert('$msg');</script>";
}
if(array_key_exists('btnRegisterAdmins', $_POST))
{
$fname = $_POST['FirstName'];
$lname=$_POST['LastName'];
if(empty($fname))
{
$alertscript = "you need...<br />";
}
if(empty($lname))
{
$alertscript = $alertscript . "<br /> to be good...";
alert($alertscript);
}
?>
The output was without a line drop and the tag itself appears. Which way can i solve this?
Upvotes: 0
Views: 748
Reputation: 842
alert(" hi \r\n i am at new line")
second occurance of <br/>
in your code is replaced with "/r"
Try
<?php
function alert($msg)
{
$msg = "'$msg'"; //to get message enclosed by single quotes
echo "<script type='text/javascript'>", //try other approach
"alert($msg);",
"</script>";
}
$arr = array("btnRegisterAdmins"=>1);
if(array_key_exists('btnRegisterAdmins', $arr))
{
$fname = ""; //guessing no fname
$lname=""; //guessing no lname
$alertscript ="";
if(empty($fname))
{
$alertscript = " you need...";
}
if(empty($lname))
{
$alertscript = $alertscript . '\r to be good...';
alert($alertscript);
}
}
?>
Upvotes: 1