faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

48 of 59 people (81%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I get JS 1.1's String.split() to use a TEXTAREA's entered VALUE's carriage/line return(s) as a delimitation character?

Apr 18th, 2000 06:59
Francois Lachance, De Rail,


The short answer is use this as the regular expression:
var re = /\r\n/g

Try the following sample:

<HTML>
<HEAD>
<TITLE>RegExp split() sample</TITLE>
<SCRIPT LANGUAGE=javascript>
<!--

function button1_onclick() {
var sTextArea = TEXTAREA1.value,

    //   This is the regular expression to use.
    re = /\r\n/g,

    aHTMLComments = sTextArea.split(re);
    for (x=0; x<aHTMLComments.length; x++)
      alert(aHTMLComments[x]);
}

//-->
</SCRIPT>
</HEAD>
<BODY>

<P><TEXTAREA name=TEXTAREA1 style="HEIGHT: 62px; WIDTH: 
300px"></TEXTAREA></P>
<P></P>
<P></P>
<INPUT name=button1 type=button value="Click Me" LANGUAGE=javascript 
onclick="return button1_onclick()">
</BODY>
</HTML>