473,231 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

<textarea> function to replace Returns and Spaces

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 &nbsp;. The <br> part works well enough, but I keep getting "%20" instead of "&nbsp;" for the spaces.

I understand that escape() changes " " to "%20", but I would think the ConvertSpaces function below would change the %20 to &nbsp;, but it doesn't. (FYI, I need &nbsp; 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&gt;')" type="image" name="add" /></form>

function ConvertCarriageReturns(textarea, strReplace)
textarea.value = escape(textarea.value)
if(textarea.value.indexOf("%0D%0A") > -1 )
textarea.value = textarea.value.replace("%0D%0A",strReplace)

function ConvertSpaces(textarea, strReplace)
textarea.value = escape(textarea.value)
if(textarea.value.indexOf(" ") > -1 )
textarea.value = textarea.value.replace(" ",strReplace)
textarea.value = unescape(textarea.value)
May 15 '07 #1
3 5587
1,208 Expert 1GB
i believe you have to replace " " in your serverside code... because it will escape it to %20 also i think.
May 15 '07 #2
Rrrggh. I was really hoping you were going to tell me I missed a semicolon or something easy like that. This is reaching beyond my realm of personal ability now.
May 15 '07 #3
5,821 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<textarea.value.length;i++)
  2. {
  3. if(textarea.value.indexOf(" ") > -1 )
  4. {
  5. textarea.value = textarea.value.replace(" ",strReplace)
  6. }
  7. }
  8. textarea.value = unescape(textarea.value)
This might not work properly, especially if, for example, two spaces are next to each other and strReplace is null.

Try this instead:

Expand|Select|Wrap|Line Numbers
  1. if(String(strReplace).indexOf(' ') > -1) {
  2.     alert('strReplace contains a space!\n"' + strReplace + '");
  3.     return false;
  4. }
  6. textarea.value = textarea.value.replace(/ /g, strReplace);
If you don't want to use regular expressions, you could just use the code you had, but without the for loop:
Expand|Select|Wrap|Line Numbers
  1. while(textarea.value.indexOf(' ') > -1)
  2.     textarea.value = textarea.value.replace(' ', strReplace);
May 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Matt | last post by:
Simple vbscript,html page loading into access. Input pg posting to Confirm pg, then sending to access. when using; <textarea name="name" tabindex="15"> </textarea> as an input renders tab...
by: Augustus | last post by:
Hiya, I have a form with a <textarea></textarea> to receive user input. This input is then stored in a database and sent by fax... I need to be able to remove the carriage returns (enter...
by: Dennis Allen | last post by:
Hi. I hope someone here can help. I'm webmaster for a local astronomy club. Just went over our web site. Have validated every htm file on the site except:...
by: Jonathan Taub | last post by:
This may seem a stupid question. I've got a <textarea> element: .... <td> List of items: <textarea> 1. Apple 2. Orange 3. Box
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
by: Jarek Mielcarek | last post by:
hi all, in xml file I have some fields which are source for <textarea> element. I'd like to transform this file using xslt and set the rows property of <textarea> depend of lines in some source...
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in...
by: Icarus - iD_Ten_T helper | last post by:
First of all, my apologies if this should be in a php newsgroup and not here, but I thought this the best place to start. I want to parse the text from a <textareaform element but when I pass...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.