473,701 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textarea and javascript

Is it possible to read each line from a HTML textarea into a
javascript array. For example:
If I were to input into the textarea:
1
4
6
3
Could I somehow have javascript read it so:
array[1]=1
array[2]=4
array[3]=6
array[4]=3

And also, is it possible to find how many lines long a textarea is?

Thanks for the help, it is greatly appreciated.
Jul 20 '05 #1
1 12231
Lee
CiscoGuy said:

Is it possible to read each line from a HTML textarea into a
javascript array. For example:
If I were to input into the textarea:
1
4
6
3
Could I somehow have javascript read it so:
array[1]=1
array[2]=4
array[3]=6
array[4]=3

And also, is it possible to find how many lines long a textarea is?

Thanks for the help, it is greatly appreciated.


Note that the first element of an array is indexed as 0,
not 1. Otherwise, this seems to be generally what you want:

<html>
<head>
<script type="text/javascript">
function textareaToArray (t){
return t.value.split(/[\n\r]+/);
}
function showArray(a){
var msg="";
for(var i=0;i<a.length; i++){
msg+=i+": "+a[i]+"\n";
}
alert(msg);
}
</script>
</head>
<body>
<form>
<textarea rows="10" cols="20" name="alpha"></textarea>
<br>
<input type="button"
value="show array"
onclick="showAr ray(textareaToA rray(this.form. alpha))">
</form>
</body>
</html>

Jul 20 '05 #2

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

Similar topics

4
5273
by: Simon | last post by:
I have another question.. Let's take a textarea with the parameter: "rows=4" (<textarea rows=4 onkeydown="CheckScrollbar()"> ) 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
6
1848
by: dan glenn | last post by:
hi. I'm having a problem using javasript to pass the value of a textarea (in a form) to a PHP script file. I want to code a 'preview' function into a guestbook entry page, using an HTML link with some javascript to grab the form's textarea value, and open another browser window that uses a php file that applies all the styles, etc. to the contents of what was in the text area (the guestbook entries allow simple HTML) and show the preview...
4
16713
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...
5
3015
by: lawrence | last post by:
How to add text to a textarea using javascript? Apparently this is a popular question, because when I run the search on google, there are a lot of returns: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&q=how+to+add+text+to+a+textarea&btnG=Search&meta=group%3Dcomp.lang.javascript However, all of the examples seem case specific, rather than generic. I'm new to Javascript, so it is not so easy for me to take a specific example and...
4
4258
by: TJS | last post by:
can the rows and columns of a textarea element with an id be changed on the fly ? if so is there an example ?
5
4575
by: bwucke | last post by:
Is there any way to scroll textarea (to the bottom row) from Javascript in Opera? The textarea.scrollTop=textarea.scrollHeight+textarea.scrollTop; approach doesn't work, and there's so many notices that it doesn't all over the net, that if there's any solution/workaround to this problem on the net, it's unfindable. Alternatively (my workaround) is there any way to reliably count lines
23
3812
by: Angus | last post by:
Hello I have a DIV with various elements eg: <div ARID="8" ARType="Char" ARDBN="Short Description"> <label class="label f9" for="arid8"Short Description</label> <textarea class="text sr " wrap="off" id="arid8" rows=1></textarea> </div> I have a variable, divs, which contains the DIV's and divs contains
6
2458
by: lamp | last post by:
Hello, I want 1 Textarea which can take only 20 characters. It can't input more than 20 characters. Please, guide me. Thanks in advance
2
3082
by: thuythu | last post by:
Please help me.... I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the textbox value in the main page is undefined ---------------------------------------- here are code main page: ------------------------------------------- <script language="JavaScript"> var thedata; var newwin; var thenumber; function...
1
2788
by: Nick | last post by:
Hi, I have created a html page from Java and I have added a .js file which can resize a TextArea inside the html on mousedown event. <script src="C:\temp\resize.js"</script> <table<tr><td onmousedown="javascript:resize('trinput',event)"> <TEXTAREA NAME="input" id="trinput" COLS=40 ROWS=60> my textarea here </TEXTAREA>
0
8649
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
9221
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8933
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5904
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
4410
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
4661
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3102
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2035
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.