Add paragraph breaks in textarea

Discussion in 'Javascript' started by ThunStorm, Mar 9, 2006.

  1. ThunStorm

    ThunStorm Guest

    I have a script that is working but I can't figure out how to add
    paragraph breaks into the textarea. Can anyone help me? If you run the
    script, the problem will be easier to understand. If possible too, can
    you let me know how to run two instances of the drop down box using the
    same array.

    <script language="JavaScript">

    var teams=new Array()

    teams[0]="Karen L. <br><br> Marlene T. <br><br> Joyce A. <br><br>
    Mickey Z.";
    teams[1]="Joan T. <br><br> June G. <br><br> Alice G. <br><br> Sandy
    B.";
    teams[2]="Mary B. <br><br> Amy S. <br><br> Carol C. <br><br> Dee V.";
    teams[3]="Bev W. <br><br> Fran D. <br><br> Barb F. <br><br> Gerry B.";
    teams[4]="Blind <br><br> Lynda F. <br><br> Gail J. <br><br> Val B.";
    teams[5]="Helen N. <br><br> Sandy S. <br><br> Pat D. <br><br> Blind";
    teams[6]="Dora F. <br><br> Yo P. <br><br> Minnie C. <br><br> Blind";
    teams[7]="<br>You Must Bowl NO <br> LESS THAN ( <INPUT TYPE=text
    NAME=PPG SIZE=2 MAXLENGTH=3> ) To <br> Take A Point Per Game!!!";
    teams[8]="Please select a team!"

    function changecontent(which){
    document.ddmessage.contentbox.value=teams[which.selectedIndex]
    }

    document.ddmessage.contentbox.value=teams[document.ddmessage.selectbox.selectedIndex]
    </script>
    </head>
    <body>


    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100%"><form name="ddmessage"><table border="1"
    width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100%"><select name="selectbox" size="1"
    onChange="changecontent(this)">
    <OPTION>Select Team</option>
    <OPTION>Alley Cats </option>
    <OPTION>Blind</option>
    <OPTION>Dreamers</option>
    <OPTION>Lucky Strikes </option>
    <OPTION>Morn D. Lites </option>
    <OPTION>Pin Pals</option>
    <OPTION>Pin Ups</option>
    <OPTION>Ups + Downs</option>
    </SELECT> <br>
    </td>
    </tr>
    <tr>
    <td width="100%"><textarea rows="8" name="contentbox"
    cols="35" wrap="virtual"></textarea><br>
    </td>
    </tr>
    </table>
    </form>
    ThunStorm, Mar 9, 2006
    #1
    1. Advertising

  2. ThunStorm

    RobG Guest

    ThunStorm wrote:
    > I have a script that is working but I can't figure out how to add
    > paragraph breaks into the textarea. Can anyone help me? If you run the
    > script, the problem will be easier to understand. If possible too, can
    > you let me know how to run two instances of the drop down box using the
    > same array.


    Add another select element just like the first.


    >
    > <script language="JavaScript">


    The language attribute is deprecated, type is required.

    <script type="text/javascript">


    >
    > var teams=new Array()
    >
    > teams[0]="Karen L. <br><br> Marlene T. <br><br> Joyce A. <br><br>
    > Mickey Z.";


    When posting code, manually wrap it at about 70 characters to allow for
    a couple of quotes without auto-wrapping introducing errors.

    textareas contain plain text, HTML in them will be displayed as plain
    text. To get new lines, replace <br> with \n.


    > teams[1]="Joan T. <br><br> June G. <br><br> Alice G. <br><br> Sandy
    > B.";
    > teams[2]="Mary B. <br><br> Amy S. <br><br> Carol C. <br><br> Dee V.";
    > teams[3]="Bev W. <br><br> Fran D. <br><br> Barb F. <br><br> Gerry B.";
    > teams[4]="Blind <br><br> Lynda F. <br><br> Gail J. <br><br> Val B.";
    > teams[5]="Helen N. <br><br> Sandy S. <br><br> Pat D. <br><br> Blind";
    > teams[6]="Dora F. <br><br> Yo P. <br><br> Minnie C. <br><br> Blind";
    > teams[7]="<br>You Must Bowl NO <br> LESS THAN ( <INPUT TYPE=text
    > NAME=PPG SIZE=2 MAXLENGTH=3> ) To <br> Take A Point Per Game!!!";


    That isn't going to work even if you fix the wrapping issue.


    > teams[8]="Please select a team!"
    >
    > function changecontent(which){
    > document.ddmessage.contentbox.value=teams[which.selectedIndex]



    You could use your 'which' reference to make that a bit shorter:

    which.form.contentbox.value=teams[which.selectedIndex];


    'which' is a property of the event object in Gecko-based browsers
    inherited from old Netscape, you may want to use a different name.
    Since it's a reference to a select element, why not 'sel' or similar?


    > }
    >
    > document.ddmessage.contentbox.value=teams[document.ddmessage.selectbox.selectedIndex]


    You can't get references to document objects that haven't been created
    yet, run it from the load event (wrapped for posting):

    window.onload = function(){
    document.ddmessage.contentbox.value =
    teams[document.ddmessage.selectbox.selectedIndex];
    }


    You should ensure that one option has a selected attribute - user agent
    behaviour if no option has a selected attribute is undefined, they may
    not all decide to make the same option selected by default.


    > </script>
    > </head>
    > <body>
    >
    >
    > <table border="0" cellspacing="0" cellpadding="0">
    > <tr>
    > <td width="100%"><form name="ddmessage"><table border="1"
    > width="100%" cellspacing="0" cellpadding="0">
    > <tr>
    > <td width="100%"><select name="selectbox" size="1"
    > onChange="changecontent(this)">
    > <OPTION>Select Team</option>
    > <OPTION>Alley Cats </option>
    > <OPTION>Blind</option>
    > <OPTION>Dreamers</option>
    > <OPTION>Lucky Strikes </option>
    > <OPTION>Morn D. Lites </option>
    > <OPTION>Pin Pals</option>
    > <OPTION>Pin Ups</option>
    > <OPTION>Ups + Downs</option>
    > </SELECT> <br>
    > </td>
    > </tr>
    > <tr>
    > <td width="100%"><textarea rows="8" name="contentbox"
    > cols="35" wrap="virtual"></textarea><br>
    > </td>
    > </tr>
    > </table>
    > </form>
    >




    --
    Rob
    RobG, Mar 9, 2006
    #2
    1. Advertising

  3. JRS: In article <>
    , dated Wed, 8 Mar 2006 17:10:53 remote, seen in
    news:comp.lang.javascript, ThunStorm <> posted :

    >I have a script that is working but I can't figure out how to add
    >paragraph breaks into the textarea. Can anyone help me?


    F.Code.value = "aa\n\nbb"

    And \t may be useful too.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Mar 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dorayme
    Replies:
    112
    Views:
    2,655
    dorayme
    Mar 30, 2009
  2. Augustus
    Replies:
    1
    Views:
    328
    Ken Schaefer
    Sep 10, 2003
  3. Paragraph breaks in forms

    , Feb 13, 2005, in forum: ASP General
    Replies:
    3
    Views:
    126
    Jeff Cochran
    Feb 15, 2005
  4. Replies:
    1
    Views:
    289
    Bart Van der Donck
    Jul 4, 2007
  5. EnjoyNews

    How to transfer breaks from a textarea ?

    EnjoyNews, Sep 12, 2008, in forum: Javascript
    Replies:
    4
    Views:
    163
    Bart Van der Donck
    Sep 16, 2008
Loading...

Share This Page