<?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.
-
What does "isn't working" mean? White screen of death?HPierce– HPierce2017年01月09日 21:24:14 +00:00Commented Jan 9, 2017 at 21:24
-
"isn't working" meaning it prints(echo) nothing, so my guess is that this code is not valid...Comrade57– Comrade572017年01月09日 21:26:07 +00:00Commented Jan 9, 2017 at 21:26
-
See: How do I get PHP errors to display?HPierce– HPierce2017年01月09日 21:27:36 +00:00Commented Jan 9, 2017 at 21:27
2 Answers 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>'
answered Jan 9, 2017 at 21:24
Jacob G
14.2k4 gold badges50 silver badges67 bronze badges
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>';
?>
default