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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.