Jump to content

Line breaks in a string


inspireddesign

Recommended Posts

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);

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/193224-line-breaks-in-a-string/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.