![]() |
|
![]() | ||
|
Subject:
JavaScript to fix line breaks in html page
Category: Computers > Programming Asked by: paul6-ga List Price: $5.00 |
Posted:
09 Oct 2002 16:24 PDT
Expires: 15 Oct 2002 21:30 PDT Question ID: 74637 |
Hello, need some help again. I have an html page at http://www.pdawax.com/GoolgeHelp.html , what you'll notice is that I have "<BR>" in all of my text boxes. what I'd like is a JavaScript that will clean this up and replace those nasty "<BR>" with real returns for both the PC and Macintosh (I don't need Unix). I've been able to find sample scripts in newsgroups, but it's taking me to long to get something. I would appreciate your assistance, thanks for helping. | |
| |
| |
|
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: JavaScript to fix line breaks in html page
From: aceresearcher-ga on 09 Oct 2002 16:44 PDT |
I think all you need to do is actually hit <enter> on your html source page after each line to get your text to come up with only one item per line. I tried that, then saved the html file to my C: drive, then called the new page up in my browser, and it looks just fine: </font><TEXTAREA NAME="printertable.spec_4_question" COLS=80 ROWS=10 wrap="virtual">1. Register marks to appear on die and all colors (minimum of 4 marks per form). 2. Res 12 (304.8 dpi) 3. N/A 4. N/A</TEXTAREA><font size="2"><br> Why don't you give that a try? Hope this helps! |
Subject:
Re: JavaScript to fix line breaks in html page
From: secret901-ga on 10 Oct 2002 18:55 PDT |
Hi Paul: I've created a short Javascript function that does what you need. Save this in a file that ends with .js, then refer to it in a <script> tag in your HTML file. Then, in the <body> tag of your HTML file, add this: onload="editPage();." I have tested this successfully on your page using IE 6.0 and Mozilla 1.0. Because it uses a system-specific character (\n), it might not work on MacIntosh though. You'd have to check. Good luck, secret901 //Begin code //Javascript to remove breaks in TextAreas //October 10, 2002 //DHN for Google Answers //All rights reserved :-) 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) { return aString.replace(/<BR>/gi, "\n"); } |
Subject:
Re: JavaScript to fix line breaks in html page
From: secret901-ga on 10 Oct 2002 19:01 PDT |
Oops, there should be NO period (.) in onload="editPage();" Sorry for the confusion. |
Subject:
Re: JavaScript to fix line breaks in html page
From: paul6-ga on 10 Oct 2002 19:46 PDT |
secret901, you have humbled me. I have no idea how to call a .js file from within a JavaScript. Could you provide me a sample? Another humble request is to provide a sample of placing the copy onload="editPage();" within the body. When I try placing the copy within the body, the copy shows up in my html page. My last humble question, I have never had to call a .js file like I stated early; do I place the .js file in the same directory as the html page? Gees from the sound of this request, it seems like I have no idea how to do any but type. Boy am I laughing out myself right now. And I thought I knew what I was doing?? Thanks for helping me, I really do appreciate this : ) |
Subject:
Re: JavaScript to fix line breaks in html page
From: secret901-ga on 10 Oct 2002 20:51 PDT |
All right, since you asked for it :-) 1. First, save the code in a file called "removeBreaks.js" or whatever you like. You can put this file anywhere you want, but to save trouble when referring to it from within the HTML file, save it in the same folder as the HTML page. 2. Edit the source of your HTML file like so (I assume that you know how to edit HTML source): See at the very top of your page, where it says <SCRIPT>? Edit it to say: <SCRIPT language = "Javascript" src="removeBreaks.js"> (edit removeBreaks.js to whatever file name that you saved the script file to. 3. Now, search where it says <body bgcolor="#e6e6fa"> and edit the line to say: <body bgcolor="#e6e6fa" onLoad="editPage();"> 4. Save your file, and that's it :-) |
Subject:
Re: JavaScript to fix line breaks in html page
From: secret901-ga on 10 Oct 2002 20:59 PDT |
By the way, I made the code in a separate file because you wanted to use this code for many pages. This way, all you have to do for any page that wants to use this code is to refer to it and call the function on loading. secret901-ga |
Subject:
Re: JavaScript to fix line breaks in html page
From: paul6-ga on 10 Oct 2002 21:12 PDT |
secret901, that's too cool. you did it. you're not going to believe this, BUT the html page is really a templaate page. how do I use the code you made for me and not have it as a soucre file? i'd like to have the code inside of the html page instead, or can i just change "src="FileName.js" to "src="http://www.pdawax.com/FileName.js". Thanks again secret901 Paul Perry |
Subject:
Re: JavaScript to fix line breaks in html page
From: secret901-ga on 10 Oct 2002 22:05 PDT |
Paul, It is quite easy to add this code directly onto the HTML file without having to refer to an external file. Copy the code and paste it into the HTML file OUTSIDE of the body (before the <body> or after the </body> tags). This can be either done by creating a new <script>...</script> tag for this new code, or just by pasting it right after the <script> tag on the first line (I prefer the latter). If you use the latter, then the beginning of your HTML file would look like this: <SCRIPT language ="Javascript"> **//My code here//** function modify(table,key) .... If you can, consider using one external file for all of your HTML files, since the pervading concept of computer science is code reuse, so I wouldn't feel right letting my code to be used this way :-). Of course, if the user will be exposed to only one HTML file, then it's quite all right to just include the code in there. Good luck with your work, secret901-ga |
Subject:
Re: JavaScript to fix line breaks in html page
From: paul6-ga on 11 Oct 2002 08:32 PDT |
secret901, i've been messing around with this all morning and i can't figure out what i'm doing wrong. could you take a look at my code http://www.pdawax.com/GoolgeHelp.html . Do you remember last time you helped me (id=68523)? you should be paid for this one too. do you have paypal? paul |
Subject:
Re: JavaScript to fix line breaks in html page
From: secret901-ga on 11 Oct 2002 09:26 PDT |
Paul, Thank you for wanting to pay me :-). Unfortunately, Google Answers policy does not allow researchers to contact clients outside of Google Answers. You can still pay me by posting a new question here, and in the subject line say "For secret901-ga only" and in the body repeat that statement, and note that anyone other than me who answers it will be rejected (researchers are very considerate to comply to clients' wishes). This will ensure that I will receive the payment. What you've done with your page is almost correct. However, since your Javascript is outside of the body, your body still needs the statement to call it when it is loaded. Remember the onload = "editPage();"? You still need it. secret901 |
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 Home - Answers FAQ - Terms of Service - Privacy Policy |