inspireddesign Posted February 24, 2010 Share Posted February 24, 2010 Hello all, I've looked before posting this and couldn't find anything that would help so I'm going to ask. My problem: I have a javascript function that does a GET request from the server. My issue is that the line breaks don't get passed to the database. They show when I alert the script. I've tried replacing the JS line breaks with <br> and inserting those but when I query the data back in the input box you could imagine that the <br> tags are there. For example: I enter information into the multiple line input box: Line 1 Line 2 The script runs OnChange (so when the input box losses focus the alert shows the correct output. When I open the input box to make changes the information in the box shows as follows: Line1Line2 which is not corrects (obviously). Is there a way to pass JS line breaks trough the browser and to the database without them getting lost? subset = The data that has the line breaks and is what is getting passed to the database. Thanks for any help on this one. function endsSub(eId, pId, subset) { subset = subset.replace(/\n/g, /<br>/ ); alert(eId + ' ' + pId + ' ' + subset); var url = "ends_submit.php?eId="+eId+"&pId="+pId+"&subset="+subset+"&action=update"; httpReqest(url) } function httpReqest(urlVar) { if(window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if(window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open("GET", urlVar, true); req.send(null); } Quote Link to comment Share on other sites More sharing options...
Tazerenix Posted February 25, 2010 Share Posted February 25, 2010 if you enter text into a textarea with line breaks it adds an invisible \n into your code. If your printing to the screen using PHP you can print the data with nl2br($data) to change those \n to <br /> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.