I want to print newline in a textarea using HTTPRequest property.
Here is my code :
<script>
function htrt(str)
{
var xmlhttp;
//document.getElementById("txtwrite").innerHTML = str;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
document.getElementById("txtwrite").value = xmlhttp.responseText;
}
}
xmlhttp.open("GET","lecture.php?techtxt=" + str);
xmlhttp.send();
}
</script>
<textarea rows="9000" cols="9000" style="height: 200px; width: 725px;" id="txtwrite" readonly="readonly"></textarea>
<textarea cols="9000" rows="9000" name="txtname" style="height: 200px; width: 725px;" onkeyup="htrt(this.value)"></textarea>
Here is lecture.php code :
<?php
$str=$_GET['techtxt'];
echo $str;
?>
It does not print newline in textarea. I have used nl2br($string) function to check what happen in the textarea but it does not work.
Please anyone help me.
Please use div instead of textarea. Because no html tags are working in textarea tag but in div it’s working.
This function
nl2br()converts new line tobrtag. Just learn this functionnl2br()well.