Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript (or CSS) textarea word wrap Firefox

Posted on 2009-07-16
3
Medium Priority
?
1,077 Views
Last Modified: 2012-08-13
I couldn't find a clear solution on this, but it seems like it would have a quick, easy answer by now.  I have a textarea field for notes.  It looks like this:

<textarea name=inspnotes cols=21 rows=13></textarea>

In firefox, the warp property is not recognized, so I need an alternative method of wrapping a user's text when they reach 21 columns.  
I found the attached javascript, and it works fine for the first line of text, but I do not understand the part of the script that uses the modulus operator, so the subsequent lines of text do not wrap properly. If there is a better way to do this other than javascript(maybe CSS), please let me know.  Thanks for reading.
<script language="javascript" type="text/javascript">
var ijk = 0;
function txt_ara()
{
//alert("1");
//alert(document.getElementById("email").value.length);
//var ijk = 0;
//var incr = 2;
if(document.getElementById("email").value.length <= 21)
{
if(document.getElementById("email").value.length == 21)
{
document.getElementById("email").value += "\n";
}
}
else
{
var lkm = "";
if(ijk == 0)
{
lkm = parseInt(document.getElementById("email").value.length % 120);  //This is what I don't understand.  What value should I set this to?
}
else
{
lkm = parseInt(document.getElementById("email").value.length % 60);  //This is what I don't understand.  What value should I set this to?
}
if(lkm == 0)
{
ijk = 1;
document.getElementById("email").value += "\n";
}
}
}
</script> 
 
<textarea name=inspnotes cols=21 rows=13 id=email onkeyup="txt_ara();" onkeydown="txt_ara();"></textarea>

Open in new window

0
Comment
Question by:thedeal56
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
level9wizard earned 2000 total points
ID: 24868983
Why not do something like this:

<!-- HTML -->
<textarea class="email"></textarea>

/* CSS */
.email
{
    display: block;
    width: 200px; /* set this to whatever you need */
}
0
 

Author Comment

by:thedeal56
ID: 24869046
Thanks for the fast reply.  BTW, your name is awesome.

Here's what I did:

.email
{
    display: block;
    width: 200px;
}

<textarea name=inspnotes cols=21 rows=13 class=email></textarea>


Still no word wrap.  
0
 

Author Comment

by:thedeal56
ID: 24898577
I started thinking about this question, and I realized that I might not have been specific enough about my problem.  The error that I'm having is when a user is inputting text the words do not wrap to the box's width.  I thought I might should clear that up, because it might have sounded like I was having trouble displaying the text rather than trouble entering it in.  
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question