I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to replace spaces with . The <br> part works well enough, but I keep getting "%20" instead of " " for the spaces.
I understand that escape() changes " " to "%20", but I would think the ConvertSpaces function below would change the %20 to , but it doesn't. (FYI, I need instead of %20 because it appears to be the only "space" code that the resulting shopping cart page will accept for multiple sequential spaces.)
I know there's lots about this on the web, but apparently I'm too unskilled to understand anything I'm finding.
<input onclick="ConvertCarriageReturns(this.form.op31,'&l t;br>')" type="image" name="add" /></form>
function ConvertCarriageReturns(textarea, strReplace)
{
textarea.value = escape(textarea.value)
for(i=0;i<textarea.value.length;i++)
{
if(textarea.value.indexOf("%0D%0A") > -1 )
{
textarea.value = textarea.value.replace("%0D%0A",strReplace)
}
}
ConvertSpaces(unescape(textarea.value),' ')
}
function ConvertSpaces(textarea, strReplace)
{
textarea.value = escape(textarea.value)
for(i=0;i<textarea.value.length;i++)
{
if(textarea.value.indexOf(" ") > -1 )
{
textarea.value = textarea.value.replace(" ",strReplace)
}
}
textarea.value = unescape(textarea.value)
}