Hello, I have been having issues when passing form variables(specifically the textarea) to a php script using the code below. My issue is that all line breaks and extra white space are deleted. It seems my trouble stems from the fact that I'm using GET in my javascript versus POST.
I was wondering if someone had a smart way to convert my javascript to use POST, or if there is another method to do this?
Thanks for any and all insight in advance!
Javascript
:
Code:
<script language="javascript" type="text/javascript">
//Browser Support Code
function submitReview(watchid){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var newtext = "Your review has been submitted to the moderator for approval.";
document.getElementById('reviewform').innerHTML = newtext;
}
}
// Now get the value from user and pass it to
// server script.
var id = document.getElementById('id').value;
var brand = document.getElementById('brand').value;
var ovr = document.getElementById('ovr').value;
var bld = document.getElementById('bld').value;
var erg = document.getElementById('erg').value;
var val = document.getElementById('val').value;
var com = document.getElementById('com').value.replace(/\n/g,'<br />');
var len = document.getElementById('len').value;
var use = document.getElementById('use').value;
var un = document.getElementById('un').value;
var mdy = document.getElementById('mdy').value;
var ytURL = document.getElementById('ytURL').value;
var price = document.getElementById('price').value;
var queryString = "?id=" + id ;
queryString += "&brand=" + brand + "&ovr=" + ovr + "&bld=" + bld + "&erg=" + erg + "&val=" + val + "&com=" + com + "&len=" + len + "&use=" + use + "&un=" + un + "&mdy=" + mdy + "&price=" + price + "&ytURL=" + ytURL;
ajaxRequest.open("GET", "sendreview.php" +
queryString, true);
ajaxRequest.send(null);
}
</script>
*EDIT* I figured this out. I added the code in red and then converted it back with a preg_replace in the PHP.