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.

3
  • What does "isn't working" mean? White screen of death? Commented Jan 9, 2017 at 21:24
  • "isn't working" meaning it prints(echo) nothing, so my guess is that this code is not valid... Commented Jan 9, 2017 at 21:26
  • See: How do I get PHP errors to display? Commented Jan 9, 2017 at 21:27

2 Answers 2

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>'
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much!
No problem, glad I could help :)
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>';
?>

3 Comments

How's this any different than my answer?
oh , You sent this answer .
yeah, I guess we both had the same idea :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.