0
<?php    
...
$name = trim($_POST["username"]);
...
echo '<script type="text/javascript">document.getElementById("message").innerHTML=
"<span style='color:red;'>'.$name.'</span> <br>login now";</script>';

?>

Why the style isn't working? When I erase the style and span the code is working fine.

Comrade57
  • 43
  • 1
  • 12

2 Answers2

2

Your need to escape the quotes around 'color:red;', that's invalid:

echo '<script type="text/javascript">document.getElementById("message").innerHTML=
"<span style=\'color:red;\'>'.$name.'</span> <br>login now";</script>'
Jacob G
  • 13,762
  • 3
  • 47
  • 67
0

Your need to escape style=\'color:red;\'

<?php
echo '<div id="message"></div>
            <script type="text/javascript">document.getElementById("message").innerHTML=
                    "<span style=\'color:red;\'>'.$name.'</span> <br>login now";</script>';
?>
Mohammad
  • 497
  • 3
  • 15