Home
Forms
Line Wrapper
Wraps entries in a textarea box to whatever number of characters per line you want. For example, The script can automatically insert a return after each 50 spaces, so that the form contents you receive are more readable. (The script does indifferently break lines in mid-word, a possible fix for the next version?)
The JavaScript Source: Forms: Line Wrapper
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!
<!-- TWO STEPS TO INSTALL LINE WRAPPER:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function showLines(max, text) {
max--;
text = "" + text;
var temp = "";
var chcount = 0;
for (var i = 0; i < text.length; i++) // for each character ...
{
var ch = text.substring(i, i+1); // first character
var ch2 = text.substring(i+1, i+2); // next character
if (ch == '\n') // if character is a hard return
{
temp += ch;
chcount = 1;
}
else
{
if (chcount == max) // line has max chacters on this line
{
temp += '\n' + ch; // go to next line
chcount = 1; // reset chcount
}
else // Not a newline or max characters ...
{
temp += ch;
chcount++; // so add 1 to chcount
}
}
}
return (temp); // sends value of temp back
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<center>
<form name=form1>
<textarea name=text1 rows=15 cols=50>This is just an example of a long textbox entry that just went on and on and on and on..... The visitor did not hit <enter> when entering this information so it continued off the right side of the textarea box. Notice that hitting <enter> after each line, like this:
This is on another line
And so is this one.....
Still wraps correctly. Neat!</textarea><br>
<input type=button value="Wrap Lines to 50 Spaces"
onClick="this.form.text1.value = showLines(50, this.form.text1.value)">
<br><br>
<textarea name=text2 rows=15 cols=50 wrap=virtual>This is another example, but this time the textarea box has the "wrap=virtual" attribute, which makes each line wrap in the box rather than scrolling out the right side. The script also correctly deals with this type of box. Like before, notice that hitting <enter> after each line, like this:
This is on another line
And so is this one.....
Still wraps correctly. Neat!</textarea><br>
<input type=button value="Wrap Lines to 50 Spaces"
onClick="this.form.text2.value = showLines(50, this.form.text2.value)">
</form>
</center>
Free JavaScripts provided
by The JavaScript Source
<!-- Script Size: 2.35 KB -->
Did you use this script? Do you like this site? Please link to us!
Comments feed