Google Answers Logo
View Question
 
Q: "For secret901-ga only" Create a JavaScript that will fix <br> problems ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: "For secret901-ga only" Create a JavaScript that will fix <br> problems
Category: Computers > Programming
Asked by: paul6-ga
List Price: $15.00
Posted: 11 Oct 2002 10:57 PDT
Expires: 10 Nov 2002 09:57 PST
Question ID: 75351
NOTE: ANYONE OTHER THAN "secret901-ga" THAT ANSWERS WILL BE
REJECTED!!!
##############################################################

Hello secret901, would you please create a JavaScript for me that will
remove all "<br>" type elements in a "text box". I have provided an
example at http://www.pdawax.com/GoolgeHelp.html. Would you also make
it so that this script can be used for other html files. What I mean,
if I want to use this for another html page (which I will) it will be
for a different name field(s). I'll need to know how to modify the
script to work with different fields (naming). but if your script will
work for any field just tell me. This script will need to work for PC,
Macintosh and Unix. Thanks BTW: thanks for pointing out that contact
between users out of Answer Google is prohibited.

Request for Question Clarification by secret901-ga on 11 Oct 2002 15:21 PDT
Hi Paul,
I don't understand what you mean by "text box."  Do you want me to
modify the code so that it would remove the <BR> in the smaller boxes?
(I don't see them having <BR>, so I thought your request was a little
strange.)
My code was designed with reuse in mind, so it works with any page
that has the TextArea in forms.  It goes through every form in the
document, then goes through every item in the forms it goes through. 
If the item is a TextArea, the code makes the necessary changes to the
text so that the <BR> is replaced by a "\n", the newline character.
Thus, if the TextAreas in your pages are inside forms (which you most
likely are, since there's no point in having a text area with no
forms), then you need to make no change.
I have tested the script on Windows with Netscape 4.8, IE 6.0, and
Mozilla 1.1.  It should work on Unix, but I am not certain about
MacIntosh, since I have no access to one to test the code.
If this is acceptable, please let me know.
Thanks
secret901-ga

Request for Question Clarification by secret901-ga on 11 Oct 2002 17:54 PDT
Program update:
I've supposedly updated my code to work on Macintoshes, but there is
no way for me to test :-(

Clarification of Question by paul6-ga on 11 Oct 2002 19:42 PDT
hi secret901, i have only been using your code on a Macintosh
environment. when i was doing research into building this script
myself, i noticed that there were perameters that you could put in the
code that would be with other os's that caused the <br> problem. but
it appears to me the way you've written the code should be fine. have
a great weekend.
paul
Answer  
Subject: Re: "For secret901-ga only" Create a JavaScript that will fix <br> problems
Answered By: secret901-ga on 11 Oct 2002 20:06 PDT
Rated:5 out of 5 stars
 
Hi Paul,
Below is the updated code for the script that is fixed for
Macintoshes. (I made changes to only one line.  If it doesn't work
this time, revert to the old version.)
To use the code in any HTML file (with a form) that you wish, just
paste it onto the head of the file, and in the <body> tag add
onLoad="editPage();"
As I stated before, this code does not depend on any field name (it
just traverse through a whole list of fields), so there should be no
problem adapting it.
If you have any installation problems with this code, please let me
know and I'll be happy to clarify.

Have a great weekend,
secret901-ga

<script language = "Javascript">
//Begin code
//Javascript to remove breaks in text areas
//October 10, 2002
//Made for Google Answers
function editPage()
{
	var formArray = document.forms;
	for(var i = 0; i < formArray.length; i++)
	{
		var currentItem;
		for(var j = 0; j < formArray[i].elements.length; j++)
		{	
			currentItem = formArray[i].elements[j];
			if(currentItem.type == 'textarea')
				currentItem.value = removeBreaks(currentItem.value);
		}
	}
	return true;
}

function removeBreaks(aString)
{
	var newLine = (navigator.appVersion.lastIndexOf('Win') != -1) ?
"\r\n" : "\n"
	return aString.replace(/<BR>/gi, newLine);
}
</script>
paul6-ga rated this answer:5 out of 5 stars
As usual "secret901" did an excellent job. His/Her (?) code is very
clean and works the first time, which implies to me that he/she (?)
test it before his/her (?) post. Which would seem logical, but
sometime people just quickly make a post to get paid (I’ve had
first-hand experience before with that happening). Thanks again
secret901 for you assistance.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy