Thursday, March 6, 2014

How to solve text area new line and space issue

When store text area content via ajax get method it's make me more stress. just storing text from text area it's no problem, but tried to allow new line and spaces it's some difficult. send text area content as  ajax argument like

?dec=document.getElementById("id").innerHTML

and store it in database. Then display the content in front end DIV new line and space not displayed. i checked with our friend google more than a hour and found the solution.

First we need to send the text area raw content so only we can get it from database for this we need to use encodeURIComponent() to encode all content so i changed like this

?dec=encodeURIComponent(document.getElementById("id").innerHTML)



To store it in db we must decode it.For decode the content we need to use like this

utf8_decode(rawurldecode($_GET['dec']));

and store it in db.

Now need to display it in front end as it's what we entered in text area so i used <pre> tag instead of <div> tag so only the spaces in content will displayed. now my problem solved.

Hope it help some one. please share your comments.

No comments:

Post a Comment