tags:

views:

22

answers:

2

Guys, could you help me with treating text sent with GET method. How to detect and treat line foldings in text? The text is sent from textarea through AJAX using GET method. How to detect line foldings in text when it is sent in GET method?

And I want to replace all line foldings with special character for example like "|" before sending to PHP script.

How to do it?

A: 
<textarea id="message"></textarea>

<script type="text/javascript">
  var msg = document.getElementById("message").value;
  msg = msg.replace(/\n/g, "|");

  // Then, just send message through AJAX.
</script>
Seb
+1  A: 

You can do this with the JavaScript string replace function.

s = "a\rb\nc\r\nd";
s2 = s.replace(/(\r\n|\r|\n)/g, "|");

s2 now equals: "a|b|c|d", no matter whether line endings are \r\n, \n, or \r.

Eloff
Eloff, great thanks! That's really I needed!
ilnur777