0

I have following variable in php which is contains paragraph with line breaks. i need to put this $messagevalue in session and access the session in jquery.

Message from textarea look likes:

enter image description here

$message    = nl2br($_POST['message']); 
$_SESSION['message'] = $message; 

So when i access paragraph with line breaks it not working, but paragraph with out line breaks, it works. What the error here?

<script type="text/javascript">    
  $(document).ready(function () {
     var subject = "<?php if(isset($_SESSION['subject'])){echo $_SESSION['subject'];} ?>"
     alert(subject);
  });
</script>
Geeth Welagedara
  • 614
  • 1
  • 8
  • 24
  • 1
    Not an answer to your question, but make sure you sanitise the user input or you are vulnerable to XSS attacks. – Alex Young Nov 24 '16 at 15:50
  • 1
    JS strings cannot cross line boundaries. To get this working you'll need to replace the line breaks with `/n` for example. [This](http://stackoverflow.com/questions/10757671/how-to-remove-line-breaks-no-characters-from-the-string) is basically what you're asking – Rory McCrossan Nov 24 '16 at 15:51

0 Answers0