Jump to content

ENTER key on textarea display n


BkJim

Recommended Posts

Hi every one,I am using textarea to insert data, but every time I press <ENTER> key, I get n on display and line doesn't change.Exp : Today. <ENTER> tomorrow.On display : Today.ntomorrow.I also try nl2br($_POST['article']) on PHP file and I get same result.How can I solve this ?Thank's in advance.

 

index.htm

<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0"> <tr> <td><textarea name="article" id="article"></textarea></td> </tr> <tr> <td><input name="submit" type="button" onclick="submitArticle();" /></td> </tr></table>

 

article.js

function getXMLHttpRequest() { var xhr = null; if (window.XMLHttpRequest || window.ActiveXObject) { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { xhr = new XMLHttpRequest(); } } else { alert("XMLHTTPRequest object cannot be support !"); return null; } return xhr;}

function submitArticle(){ var xhr = getXMLHttpRequest(); var article = encodeURIComponent(document.getElementById('article').value); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { document.getElementById('article').innerHTML = xhr.responseText; } }; xhr.open("POST", "Article.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("&article="+article);}

 

article.php

if (isset($_POST['article']) && !empty($_POST['article'])){ $sql = 'INSERT INTO article VALUES("", "'.$_POST['article'].'")'; mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error());}

 

Link to comment
Share on other sites

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>textarea</title><script>window.onload = init;function init(){document.getElementById('btn').onclick = xfer;document.getElementById('txtin').value = 'anbnc';}function xfer(){var txt = document.getElementById("txtin").value;txt = txt.replace(/n/g,"<br/>")document.getElementById("out").innerHTML = txt;}</script></head><body><textarea id="txtin" cols="80"></textarea><br/><br/><input type="button" id="btn" value="Enter"/><br/><br/><div id="out"></div></body></html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...