I have a simple html that goes to a asp script to save the data in a text file but all the spaces disappear. I have tried a lot.
I have tried to do a URL coding but it does not fix it. Server.URLEncode is still in the script.
I really need to under how to get the blanks in the output file. Please help
any help.
This is the script from the HTML
<script type="text/javascript">
// Current date - http://stackoverflow.com/a/4929629/412329
// this creates the date and time for the save file
//end create time and date stamp
function saveFormAsTextFile()
// Based on https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/
{
var today = new Date();
var s = today.getSeconds();
var n = today.getMilliseconds();
var dd = today.getDate();
var mm = today.getMonth() 1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0' dd;
}
if(mm<10) {
mm='0' mm;
}
today = yyyy '-' mm '-' dd '-' s '-' n;
//This section checks to see if the quantity is zero and sets it to 1
var copies;
copies = 1;
//copies = document.getElementById('Quantity').value;
if (copies < document.getElementById('Quantity').value)
{
var copies = document.getElementById('Quantity').value;
}
//end copies section
var Line1 = document.getElementById('Line1').value;
var textToSave =
'datestring=' today
'&SKU=' document.getElementById('SKU').value '\n' // =SKU
'&Form=' document.getElementById('Select_Form').value // =Select Form
'&Printer=' document.getElementById('Select_Printer').value // =Select Printer
'&Retail=' document.getElementById('Retail').value // =Select Retail
'&Sale_Price=' document.getElementById('Sale_Price').value // =Select Sale_Price
'&Pieces=' document.getElementById('Pieces').value // =Select Pieces
'&Line1=' Line1 // =Select Line1
'&Line2=' document.getElementById('Line2').value // =Select Line2
'&Line3=' document.getElementById('Line3').value // =Select Line3
'&Line4=' document.getElementById('Line4').value // =Select Line4
'&Line5=' document.getElementById('Line5').value // =Select Line5
'&Line6=' document.getElementById('Line6').value // =Select Line6
'&Copies=' copies
var xhr=new XMLHttpRequest();
xhr.open("POST", "Gallery_Tags_Print-OTF.asp", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(textToSave);
alert("Sent to printer!");
}
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
This is the full asp
<%
dim fs, tfile
datestr=Request.Form("datestring")
sku=Request.Form("SKU")
form=Request.Form("Form")
printer=Request.Form("Printer")
retail=Request.Form("Retail")
saleprice=Request.Form("Sale_Price")
pieces=Request.Form("Pieces")
line1=Request.Form("Line1")
test2=Server.URLEncode(Request.Form("Line1"))
line2=Request.Form("Line2")
line3=Request.Form("Line3")
line4=Request.Form("Line4")
line5=Request.Form("Line5")
line6=Request.Form("Line6")
copies=Request.Form("Copies")
filestr="C:\Program Files\FabSoft-SysConnect\Spooler\" & datestr & ".txt"
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(filestr, true)
tfile.WriteLine( "")
tfile.WriteLine( "")
tfile.WriteLine( "")
tfile.WriteLine( "")
tfile.WriteLine( "")
tfile.WriteLine("did it work: " & test2)
tfile.WriteLine( "")
tfile.WriteLine( "")
tfile.WriteLine( chr(9) & chr(9) & chr(9) & chr(9) & chr(9) & chr(9) & chr(9) &" OTF-TEMPLATE")
tfile.WriteLine( chr(9) & "SKU: " & sku)
tfile.WriteLine( chr(9) & "Form: " & form)
tfile.WriteLine( chr(9) & "Printer: " & printer)
tfile.WriteLine( chr(9) & "Retail Price: " & retail)
tfile.WriteLine( chr(9) & "Sale Price: " & saleprice)
tfile.WriteLine( chr(9) & "Pieces: " & pieces)
tfile.WriteLine( chr(9) & "Line 1: " & line1)
tfile.WriteLine( chr(9) & "Line 2: " & line2)
tfile.WriteLine( chr(9) & "Line 3: " & line3)
tfile.WriteLine( chr(9) & "Line 4: " & line4)
tfile.WriteLine( chr(9) & "Line 5: " & line5)
tfile.WriteLine( chr(9) & "Line 6: " & line6)
tfile.WriteLine( chr(9) & "Copies: " & copies)
tfile.close
%>
CodePudding user response:
Try using encodeURIComponent() on the user inputted fields like the following. Also not sure why you have the "\n" getting added.
var textToSave =
'datestring=' encodeURIComponent(today)
'&SKU=' encodeURIComponent(document.getElementById('SKU').value) // =SKU
'&Form=' encodeURIComponent(document.getElementById('Select_Form').value) // =Select Form
'&Printer=' encodeURIComponent(document.getElementById('Select_Printer').value) // =Select Printer
'&Retail=' encodeURIComponent(document.getElementById('Retail').value) // =Select Retail
'&Sale_Price=' encodeURIComponent(document.getElementById('Sale_Price').value) // =Select Sale_Price
'&Pieces=' encodeURIComponent(document.getElementById('Pieces').value) // =Select Pieces
'&Line1=' Line1 // =Select Line1
'&Line2=' encodeURIComponent(document.getElementById('Line2').value) // =Select Line2
'&Line3=' encodeURIComponent(document.getElementById('Line3').value) // =Select Line3
'&Line4=' encodeURIComponent(document.getElementById('Line4').value) // =Select Line4
'&Line5=' encodeURIComponent(document.getElementById('Line5').value) // =Select Line5
'&Line6=' encodeURIComponent(document.getElementById('Line6').value) // =Select Line6
'&Copies=' encodeURIComponent(copies)
CodePudding user response:
That was the solution encodeURIComponent
'&SKU=' encodeURIComponent(document.getElementById('SKU').value) // =SKU