Jump to content

Saving a text area field to DB via Web Service [SOLVED]


radi8
 Share

Recommended Posts

Good day list!I have a form that I am using JS to update a DB via a web service. The code is very basic and straight forward as so:

function doRoute11(leg){		var id	  =  document.getElementById('ShipmentNbr').value;		var bol	 = 0;		var notes   = '';		var delDate ='';		var rows	= document.getElementById('drops').getElementsByTagName('tr');		bol		 = rows[leg].cells[2].childNodes[0].value;		delDate	 = rows[leg].cells[6].childNodes[1].value;		notes	   = rows[leg].cells[7].childNodes[0].value;				if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari				xmlhttp=new XMLHttpRequest();		}		else{// code for IE6, IE5			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");		}		xmlhttp.onreadystatechange=function(){			if (xmlhttp.readyState==4 && xmlhttp.status==200){								var resp = xmlhttp.responseText;				// do stuff with responceText	   			}		}		// process the input, be sure to escape all manual entries	   	   xmlhttp.open("GET","<?php print 'http://'.$_SERVER['HTTP_HOST'].'/webServices/'?>update_Routes.inc.php?id="+id+"&type=11&bol="+bol+"&notes="+notes,true);	   xmlhttp.send();	}

Notice the one field called notes. This field is a text area field and may have some text in it like:"This is some text\n\nwith multiple lines" (the \n\n indicates 2 line feeds).In this function, the notes element does indeed have the line feeds in it, but when passed into the php db script, the line feeds are stripped out, so the text is: "This is some textwith multiple lines"Is there a way to prevent this? I know it must be something simple, but I am not finding the solution.

Edited by radi8
Link to comment
Share on other sites

notes="+encodeURIComponent(notes)You'll want to use encodeURIComponent for any user-supplied data going into a URL.
OUTSTANDING YOUNG MAN (or Old man if such is the case)! That worked perfectly!Thanks so much for the help. Edited by radi8
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
 Share

×
×
  • Create New...