473,666 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textarea, maybe an other way

I have another question..
Let's take a textarea with the parameter: "rows=4"
(<textarea rows=4 onkeydown="Chec kScrollbar()"> )

If you start typing the scrollbar at the right is not active. Only when you
exceed the four lines (rows=4) the scrollbar becomes active.
That moment..the moment the scrollbar becomes active..can javascript
recognize/capture this moment?
Thanks, Simon
Jul 20 '05 #1
4 5264
You can do that, try this example (tested on IE6):

<html>
<head>
<script type="text/javascript">
var savedValue="";
function CheckScrollbar( ){
var nomoretext=fals e;
var str = document.getEle mentById("nomor ethanxrows").va lue;
var lines = str.split("\n") ;
var allowedLines =
document.getEle mentById("nomor ethanxrows").ge tAttribute("row s");
var allowedCols =
document.getEle mentById("nomor ethanxrows").ge tAttribute("col s")
if (lines.length > allowedLines){
nomoretext=true
}
var howmanyrows=0;
for (var i = 0; i<lines.length ; i++){
var onelinelength =
(i==lines.lengt h-1)?lines[i].length:lines[i].length-1;
if (onelinelength > allowedCols)
howmanyrows += Math.ceil(oneli nelength/allowedCols);
else
howmanyrows++;
if (howmanyrows > allowedLines)
nomoretext=true ;
}
if (nomoretext){
alert("No more text in my house.");
document.getEle mentById("nomor ethanxrows").va lue = savedValue;
}
}
function SaveValue(){
savedValue=docu ment.getElement ById("nomoretha nxrows").value;
}
</script>
</head>

<body>
<textarea id="nomorethanx rows" rows="4" cols="15" onkeypress="Sav eValue()"
onkeyup="CheckS crollbar()"></textarea>
</body>
</html>

"Simon" <si*******@plan et.nl> wrote in message
news:bf******** **@reader10.wxs .nl...
I have another question..
Let's take a textarea with the parameter: "rows=4"
(<textarea rows=4 onkeydown="Chec kScrollbar()"> )

If you start typing the scrollbar at the right is not active. Only when you exceed the four lines (rows=4) the scrollbar becomes active.
That moment..the moment the scrollbar becomes active..can javascript
recognize/capture this moment?
Thanks, Simon

Jul 20 '05 #2
Thanks a lot!!!!!
You are great!
"Vjekoslav Begovic" <vj*******@inet .hr> schreef in bericht
news:bf******** **@sunce.iskon. hr...
You can do that, try this example (tested on IE6):

<html>
<head>
<script type="text/javascript">
var savedValue="";
function CheckScrollbar( ){
var nomoretext=fals e;
var str = document.getEle mentById("nomor ethanxrows").va lue;
var lines = str.split("\n") ;
var allowedLines =
document.getEle mentById("nomor ethanxrows").ge tAttribute("row s");
var allowedCols =
document.getEle mentById("nomor ethanxrows").ge tAttribute("col s")
if (lines.length > allowedLines){
nomoretext=true
}
var howmanyrows=0;
for (var i = 0; i<lines.length ; i++){
var onelinelength =
(i==lines.lengt h-1)?lines[i].length:lines[i].length-1;
if (onelinelength > allowedCols)
howmanyrows += Math.ceil(oneli nelength/allowedCols);
else
howmanyrows++;
if (howmanyrows > allowedLines)
nomoretext=true ;
}
if (nomoretext){
alert("No more text in my house.");
document.getEle mentById("nomor ethanxrows").va lue = savedValue;
}
}
function SaveValue(){
savedValue=docu ment.getElement ById("nomoretha nxrows").value;
}
</script>
</head>

<body>
<textarea id="nomorethanx rows" rows="4" cols="15" onkeypress="Sav eValue()"
onkeyup="CheckS crollbar()"></textarea>
</body>
</html>

"Simon" <si*******@plan et.nl> wrote in message
news:bf******** **@reader10.wxs .nl...
I have another question..
Let's take a textarea with the parameter: "rows=4"
(<textarea rows=4 onkeydown="Chec kScrollbar()"> )

If you start typing the scrollbar at the right is not active. Only when

you
exceed the four lines (rows=4) the scrollbar becomes active.
That moment..the moment the scrollbar becomes active..can javascript
recognize/capture this moment?
Thanks, Simon


Jul 20 '05 #3
AAAAARRRGGGHHHH HHH!!!!!!!!!!!! !!!!

Sorry, but thats how much I was frustrated when I could not get a
simple thing to work on a static html page using javascript. I just
wanted to insert a line break into the textarea dynamically. Here is
the piece of code that will not work... but will give you a "unknown
runtime error". If you remove the "<br>"s, it will work.

<html>
<head>
<script language="JavaS cript">
function writeText() {
document.all.my TextArea.innerH TML =
"Hello<br>" + "sometext" + "<br>Hello" ;
//THIS WONT WORK EITHER:
//document.all.my TextArea.innerH TML =
// "Hello\n" + "sometext" + "\nHello";
}
</script>

</head>
<body>
<table>
<tr><td id="mytd"><text area
id="myTextArea" ></textarea></td></tr>
<tr><td><inpu t type="submit" name="submit" value="submit"
onClick="writeT ext();"/></td></tr>
</table>

</body>
</html>


But Internet Explorer did not like it. I visited a lot of newsgroups
and tried different things. I've tried replacing line breaks ("\n")
with <br>s and what not... but we wont go into it. What I am trying
to
say here is that I could not find a way to format the text inside a
text area. After hours of research, I just ended up doing something
like this... which by the way occured to me when I was finishing up
my
Dominos pineapple pizza. The workaround was to include the whole
textarea inside the javascript and write them into the TD using the
innerHTML of the TD at runtime. I sincerely hope that this will help
someone solve a similar issue and save them a lot of trouble.

=========
SOLUTION:
=========

Here is the code that I came up with to work around this situation...
//THIS IS THE WORKAROUND: (result is the id of TD, so you are
basically inserting html that CONTAINS the textarea into the TD
instead of writing text to the textarea. i.e., you are writing the
whole textarea into the TD at runtime)

<html>
<head>
<script language="JavaS cript">
function writeText() {
var rslt;
rslt = "<textarea id=\"myTextArea \">";
rslt += "Hello\n" + "sometext" + "\nHello";
document.all.my td.innerHTML = rslt + "</textarea>";
}
</script>

</head>
<body>
<table>
<tr><td id="mytd"> <textarea id="myTextArea" ></textarea>
</td></tr>
<tr><td><inpu t type="submit" name="submit" value="submit"
onClick="writeT ext();"/></td></tr>
</table>

</body>
</html>
GOOD LUCK!!!

You are welcome.

Jawad Shaik Mohammed
Stryker Instruments
Kalamazoo, MI
Ph: (269) 323-7700 x3500
Jul 20 '05 #4
"Simon" <si*******@plan et.nl> wrote in message
news:bg******** *@reader11.wxs. nl...
Vjekoslav..
You've been very helpful sending me this script, it workes well but i have a question.
When I type text in this textarea without hiiting return on my keyboard it's possible to exceed the limit off lines.
For example a textarea with your code and a maximum of 4 rows:
[textarea]
1111111111111
2222222222222
3333333333333
4444444444444
When I would go on typing (55555555555) i could get to the 5th line without an alert!
Could you perhaps look into that? It's very important to me that no one can exceed the limit in lines set by the rows.

Thank you in advance,
Simon


If you know the number of columns as well as the number of rows, you can
also trap the number of characters from being exceeded. The total possible
number of characters is the product of rows and columns. You can check how
many characters are in a form element like this:

tbox = document.getEle mentById('somet extbox');
if(tbox.value.l ength > (rows * cols)) {
tbox.value = tbox.value.slic e(0, -1);
alert('I\'m watching you! Stop typing, and read the form
description.');
}

This would work in conjunction with the line break ("\n") checks since that
means the rows are being ended "prematurel y" and therefore can not exceed
the total number of characters in your text box.

By the way, if this is "very important," you can't count on JavaScript to
keep people from turning scripting off and pasting a copy of "The Complete
Works of Shakespeare" in your textarea. You should also check the length of
user input in your form handler on the server. If this is only "mildly
important," you can probably trust JavaScript to only goof on you <10% of
the time.

HTH,
Zac
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6177
by: Gadrin77 | last post by:
I noticed when displaying the contents of a CDATA node inside a TEXTAREA using MSXML and XSL, I get an extra space before the data. at first I thought I hadn't "tightened up" the XSL, but then even when I did this... <textarea rows="24" cols="80"><xsl:value-of select="/Root/Child/Data"/></textarea>
4
11186
by: dekern | last post by:
I have been trying to set the default text value of a TextArea element for about a day now without any luck. Similar to the code used to set the Text field below I would like to use the returned (for lack of a better term) value in a TextArea element ie. {TITLE}. this works: <input readonly="true" value="{TITLE}" name="titleedit" size="50" maxlength="255" class="detaileditentry">
4
16688
by: Csaba Gabor | last post by:
What I'd like to do is to be able to set the font of a textarea element to the same font that another element is using (say, for example, an <INPUT type=text ...> element, but if that's a no go, then a generic element's font will do OK, too. What's the correct way to do this, please (so that it will also work for IE 6)? The motivation for this is that I have some text on the screen and I want to insert a textarea element between the...
4
23713
by: Chris Sharman | last post by:
I haven't specified fonts, leaving the user to have their chosen font. However, different tags render in different default fonts: text, input, & textarea all different from one another. I guess this is normal behaviour, but it looks poor, and I don't want our website to look that way (to out of the box browsers). How would I set textarea's 'like' input, or how would I determine (Javascript?) what's being used by an input field, to set...
5
12133
by: Jesper Rønn-Jensen | last post by:
I have a textarea that must be limited to 70 characters. No big deal -- at least so I thought. * Textarea must not exceed 70 characters * Exceeding content must be cut off * Must work on input by keyboard (keypress, keyup events) * Must work on pasted input from context menu * Must work on pasted input via CTRL+V and similar * Must work on pasted input via browsers menu>Edit>Paste * Must work in Mozilla + IE and coded via W3C standards
8
52998
by: Mark D. Smith | last post by:
Hi I have googled but not found a solution to wordwrap in a textarea using firefox/netscape. is there a style sheet solution or am i stuck with not being able to force wrapping in a textarea Mark
6
31431
by: Tony | last post by:
The w3schools HTML tag reference for <textarea> http://www.w3schools.com/tags/tag_textarea.asp says that the attributes 'cols' and 'rows' are REQUIRED attributes for the textarea tag. Looking at the HTML 4.01 specification I see this, too. What I'm wondering is - 'cols' & 'rows' determines the height & width of a textarea. So shouldn't that be something that is handled by CSS instead? What would be the practical consequence of leaving...
7
3836
by: Fabien LE LEZ | last post by:
Hello, I'd like to put, on a web page, a "place" where the user can type a rather long text, with automatic coloring of each word (e.g. a color depending on the number of letters of the word). The only solution I could think of is rather ugly: a <textareafor the user to type in, and behind the <textarea>, one <spanfor each word, with the same text and font, and a colored background. I've put it there:...
3
8171
by: zjw2112 | last post by:
Hello. I have some javascript code that dynamically creates a textarea and sets the wrap value to hard, which I thought would preserve CR/LF in the textarea: var otherTextArea = document.createElement("textarea"); otherTextArea.setAttribute("rows", "10"); otherTextArea.setAttribute("cols", "30"); otherTextArea.setAttribute("id", "otherTextArea"); otherTextArea.setAttribute("wrap", "hard");
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.