Wrap Lines After X Number Of Characters In A Textarea But NOT In The Middle Of A Word

Jul 14, 2010

I have a textarea with a specific width. I have wrap="off" set because I don't want to force my users to wrap if they don't want to. The reason for this is because this textarea is where the user is typing an email message. However I have a background image set on the textarea with a verticle line going down the textarea which indicates to the user the "Recommend Width"What I want to do is provide them with a link to click on which says something like "Wrap Lines" and when they click on it, the text within the textarea would wrap to the "Recommended Width" line in the background image. The maximum length of a line should be 53 characters when they click on "Wrap Lines" link.So I did some searching around and the code I came up with is:

function showLines(max, text) {
text = "" + text;
var temp = "";
var chcount = 0;


View 5 Replies


JQuery :: Word Wrap A Textarea At X Number Of Characters?

Jul 14, 2010

I am currently seeking help on how to best approach finding a solution to this. Essentially I have a textarea which a user is supposed to be typing a text based email message(no HTML) The textarea has a column width of 80 However there is a recommended width of 53 characters per line. Obviously the user can just keep on typing away past the 53 character recommended width if they want, but I want to add either a form button or a link with an onClick thatanalyzes the contents of the textarea. It should insert a hard return when it reaches 53 characters, but if the 53rd character is in the middle of a word it should count back to the previous space and do the line wrap there.

Can anyone point me in the right direction? I assumed there has to a solution using jQuery, but I am at a loss. I did come across some javascript which works, but it doesn't take into account the fact that the 53rd character maybe in the middle of a word.


View 2 Replies View Related

Textarea Wrap Hard And Counting Lines

Jan 5, 2007

Is there any way of counting, on the onkeyup event of a textarea, the number of lines?
I tried with a split, but the wrap doesn't seem to insert any char I could split on?

View 9 Replies View Related

Limit Lines And Characters In A Textarea?

Dec 13, 2011

I have the following requirement for a textarea:Limit the number of lines to 8 Limit the number of characters to 20 per line Force a line beak when the user reaches he end of a line but break the line at the start of the last word (not half way through the word).Allow pasting into the field and auto-format the line/character countKeep he cursor where it should be (don't move it to the end of the field after any formatting)

View 6 Replies View Related

Textarea Control - Limit Characters And Lines Entered By Users?

Oct 27, 2009

I have a script that limit characters and lines entered by users in a textarea.. I want instead of throwing that alert message to jump to the next line and the user can continue writing, here is the script:

<script type="text/javascript">
var alert_title='Input Restriction';
function limitTextarea(el,maxLines,maxChar){
var lines=el.value.replace(/
/g,'').split(' .....

<textarea onFocus="limitTextarea(this,5,40)" wrap="soft">

View 2 Replies View Related

Display Number Of Characters In Textarea Box

Sep 11, 2005

i wish to count number of characters in textarea box during typing in and display it somewhere in html page. so the number will increase during writing. is it possible to do it by javascript?

View 6 Replies View Related

JQuery :: Wrap New Lines With <p> Tag

Jul 4, 2010

I want to jQuery to format the following [code]...Wrap new lines with <p> tag

I have read a zillion posts and some that are similar but have not been able to translate them into my problem.

View 6 Replies View Related

Word Wrap Not Working In FF?

Apr 6, 2009

I have a JS function that is susposed to toggle word wrap on and off in a textarea. It works fine in IE but does not work in FireFox or Opera.

Does anyone know what the trick is to get it to work in FF and Opera?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script type="text/javascript">


Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.

1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:

View 2 Replies View Related

Document.write Output Won't Stay Inside Div / Get Values To Word-wrap When They Get To End Of Container?

Jun 21, 2010

I want to use document.write to output the values of an array. If the array is too long, it totally ignores the width of the container div. How do I get the values to word-wrap when they get to the end of the container?

I've searched on this forum, and also googled for the answer but can't find a solution. I'm still fairly new to Javascript.

View 4 Replies View Related

Find Factors Of Number And Pick Two Closest To Middle?

Mar 10, 2011

Basically I want to factor a number and select the two closest numbers to the middle of the factors for example: 20 factors to 1, 2, 4, 5, 10, 20 I want it to return 4 and 5 If the number is has an odd number of factors (has to be a perfect square) I want it to select the middle number and say it twice for example:

64 factors to 1, 2, 4, 8, 16, 32, 64

I want it to return 8 and 8 Would I use an array or what? My code should probably look like:


View 21 Replies View Related

Wrap Text In A Textarea In FF?

Jun 1, 2009

Is there any way that I can make a textarea wrap in firefox? I've tried this:

calculateLines: function(text){
text = text.split('
temp = '';
chcount = tchs = c= 0;


View 5 Replies View Related

Numbered Lines In A Textarea

Mar 31, 2006

I'm trying to make a small in page editor and was wondering if there is anyway to add line numbers to my textarea. Does anyone have a solution?

View 1 Replies View Related

Wrap Attribute Of The <textarea> Element

Apr 7, 2011

I just have a question regarding the wrap attribute of the <textarea> element. I am using Programmer's Notepad. I am doing an example using the split() method in JavaScript. On the <textarea> element, it has specified that I use the 'wrap' attribute, yet when I enter this code, my attribute highlights red (which usually means that you have made a spelling mistake with the element/attribute). Now, obviously I know I haven't spelt wrap wrong and it certainly tells me in this book that you can use this attribute, so is this attribute deprecated?

View 1 Replies View Related

How To Wrap A Selected Text In A TextArea

Jul 27, 2011

I searched about this problem over Internet and found the same result many times, I found this example on stackoverflow [URL] but this example didn't work in my project; I am making a toolbar with buttons that insert HTML tags around the selected text in a <textarea>, this exemple didn't work because when the user click on a button the selected text won't be selected anymore because <textarea> loses focus and selected text will be unselected, I am targeting Firefox and compatible browsers so you don't need to give me the IE code; jQuery codes are accepted;

View 2 Replies View Related

Change 'wrap' Attribute For Textarea

Mar 8, 2010

I would like to be able to change the "wrap" attribute for a textarea with javascript. That is unless you can provide a cross browser solution in css2, giving me the ability to just modify the css attributes.

View 3 Replies View Related

Switch Textarea Wrap Realtime

Oct 24, 2005

I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does not listen to the textarea.wrap = 'soft' command. Because I want the script to be cross-browser compatible, someone suggested to remove and immediately add a node to the DOM, so I now have: Code:

View 3 Replies View Related

JQuery :: How To Wrap Text Inside Textarea

Apr 14, 2010

[URL]..I want to wrap some html code to user's selected text inside the textarea, I tried the code in above url but it seems not work in IE, is there a plugin of any way to make it work?

View 2 Replies View Related

Count The Number Of Lines In A File..

Nov 6, 2001

Does anyone know how I could (in javascript, or any client-side lang) cound the number of lines in a given textfile?

View 1 Replies View Related

How Do I Determine The Number Of Lines Displayed In Browser?

Oct 2, 2005

If I had a webpage that displayed a database in tabular form, it would
be nice to know how many lines of text the browser could display
without scrolling, then have the cgi script output the appropriate
number of lines of data to fill the screen.

I've seen examples of how to get the browser window size in pixels, but
is there a way to determine the number of lines that are displayed?

View 1 Replies View Related

Firefox - Select A Word And Wrap [b] Tags Or [quote] Tags Around It

Dec 28, 2010

I use Firefox and am wondering how to select a word and wrap [b] tags or [quote] tags around it?

View 30 Replies View Related

Stop The Replace() Function From Replacing Characters Inside A Word

Jan 4, 2010

I'm just wandering, how can you stop the replace() function from replacing characters inside a word, such as, if I try to replace 'x' with 'and', then my string would go from 'example, x' to 'eandample, and'.

View 5 Replies View Related

JQuery :: Check Number Of Lines And Altering Other Div To Match?

May 10, 2011

Trying to check how many lines a div has and then alter another to match.

Found this code, but I'm not sure what to do [code]...

Look at Navigation and then look at Animated Menus as an example. When the grey animated menus (div.columnrt) takes up two lines (could be more), need the corresponding left div (div.columnleft) to be same number of lines, so that everything stays lined up. Each of these pairs sits inside of a li element.

View 2 Replies View Related

Make A Word Limit In Textarea ?

Dec 22, 2010

I want to make a word limit on textarea in the below.

editing below code:

View 14 Replies View Related

Number To Word Translator

Aug 22, 2002

Don't know if there is one of these online, so I made me own. Simple function that outputs a number as words. First argument is the number, second argument is flag (default = false) that controls whether output is cardinal or ordinal - as in "one" or "first".

Goodness knows if I have the grammer correct, especially when the numbers get big. Enjoy!


1) Doesn't work with WebTV or below NS 4. Changing the large literal array into a common array should fix that, but I didn't bother.

2) Converts number into an integer before wording number. So, no "one point forty-five" stuff. This function is a good start for anyone who wants to do that though.

3) Always returns, "zero" for 0. Couldn't find cardinal equivalent to "zero"... zeroeth?

Num2Word, ouputs written number in human language format
Nbr: num, the number to be worded. This number is converted into an integer.
Crd: bol, flags whether output is cardinal or ordinal number. Cardinal is used when describing the order of items, like "first" or "second" place.
function Num2Word(num,fmt) {
//_ arguments
num = Math.round(num).toString(); // round value
if (num == 0) return 'zero' // if number given is 0, return and exit
//_ locals
// word numbers
var wnums = [['hundred','thousand','million','billion','trillion','zillion'],['one','first','ten','','th'],['two','second','twen',0,0],['three','third','thir',0,0],['four','fourth',0,0,0],['five','fifth','fif',0,0],['six','sixth',0,0,0],['seven','seventh',0,0,0],['eight','eighth','eigh',0,0],['nine','ninth',0,0,0],['ten',],['eleven',],['twelve','twelfth'],['thirteen',],['fourteen',],['fifteen',],['sixteen',],['seventeen',],['eighteen',],['nineteen',]];
// digits outside triplets
var dot = (num.length % 3) ? num.length % 3 : 3;
// number of triplets in number
var sets = Math.ceil(num.length/3);
// result string, word as number
var rslt = ''
//_ convert every three digits
for (var i = 0; i < sets; i++) { // for each set of triplets
// capture set of numbers up to three digits
var subt = num.substring((!i) ? 0 : dot + (i - 1) * 3,(!i) ? dot : dot + i * 3);
if (subt != 0) { // if value of set is not 0...
var hdec = (subt.length > 2) ? subt.charAt(0) : 0; // get hundreds digit
var ddec = subt.substring(Math.max(subt.length - 2,0),subt.length); // get double digits
var odec = subt.charAt(subt.length - 1); // get one's digit
// hundreds digit
if (hdec != 0) rslt += ' ' + wnums[hdec][0] + '-hundred ' + ((fmt && ddec == 0) ? 'th' : '');
// add double digit
if (ddec < 20 && 9 < ddec) { // if less than 20...
// add double digit word
rslt += ' ' + ((fmt) ? ((wnums[ddec][1]) ? wnums[ddec][1] : wnums[ddec][0] + 'th') : wnums[ddec][0]);
} else { // otherwise, add words for each digit...
// add "and" for last set without a tens digits
if ((0 < hdec || 1 < sets) && i + 1 == sets && 0 < ddec && ddec < 10) rslt += 'and '
// tens digit
if (19 < ddec) rslt += wnums[ddec.charAt(0)][(wnums[ddec.charAt(0)][2]) ? 2 : 0] + ((i + 1 == sets && odec == 0 && fmt) ? 'tieth' : 'ty') + ((0 < odec) ? '-' : ' ');
// one's digit
if (0 < odec) rslt += wnums[odec][(i + 1 == sets && fmt) ? 1 : 0];
// add place for set
if (i + 1 < sets) rslt += ' ' + wnums[0][sets - i - 1] + ' ' // if not last set, add place
} else if (i + 1 == sets && fmt) { // otherwise, if this set is zero, is the last set of the loop, and the format (fmt) is cardinal
rslt += 'th' // add cardinal "th"
//_ return result
return rslt

Test the result of various valies like so

for (var i = 0; i < 50; i++) {
var x = Math.round(Math.random() * 5000000);
document.write(x,' -> ' + Num2Word(x).bold(),'<BR>');

Use this function towards whatever means you deem necessary. Pease credit me, Bemi Faison, if you use this script.

View 3 Replies View Related

AJAX :: Textarea Word Not Appearing In Url Through It / Solution For This?

Feb 4, 2009

I used AJAX in this link code...

You have to go open the navigation box on the top left (sorry I have to simplify this in the future!) and then click the third link Compare Two Bible Texts. Once you enter a word in the first textarea and select the book, chapter, and verse it doesn't record it in the textbox underneath the verse dropdown select.

Anything wrong with this AJAX code?code...

View 1 Replies View Related

Dynamically Turn Textarea Word Wrapping On And Off

Mar 26, 2009

I'm trying to dynamically turn textarea word wrapping on and off and have the textarea update accordingly but my code isn't working and I'm not sure why.

View 4 Replies View Related

Copyrights 2005-15 www.BigResource.com, All rights reserved