Results 1 to 2 of 2

Thread: textarea to textarea using the getelementbyid method

  1. #1
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default textarea to textarea using the getelementbyid method

    Need help tweaking this script to use textarea input instead of a dropbox.
    Please and thanks to all replys

    <html>
    <head> <SCRIPT LANGUAGE="JScript">
    val='';
    function fnAdd(obj){
    if (obj.selectedIndex<0||val.match(obj.options[obj.selectedIndex].value)){ return; }
    val+=obj.options[obj.selectedIndex].value+'\n';
    document.getElementById('fred').value=val;
    }
    </SCRIPT>

    <title></title>
    </head>

    <body>


    <SELECT ID=someText>
    <OPTION VALUE="">some text</OPTION>
    <OPTION VALUE="some text1">some text1</OPTION>
    <OPTION VALUE="some text2">some text2</OPTION>
    <OPTION VALUE="some text3">some text3</OPTION>

    </SELECT>
    <INPUT TYPE=button VALUE="Add To Textarea" onclick="fnAdd(document.getElementById('someText'));">

    <textarea id="fred" rows="10" cols="20">

  2. #2
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    lgk... Try this one out, this will verify once you add one or more elements to the form and on line 26 change the one to how many elements you want to show/verify.


    <html lang="en">
    <head>
    <title>JavaScript - Example form</title>

    <style type="text/css">
    <!--
    table td {font: 14px arial;}
    -->
    </style>

    <script language="javascript">
    <!--

    // This is the check script

    function checkit()
    {
    // In textstring I gather the data that are finally written to the textarea.

    var textstring = '';

    // First of all, have all the text boxes been filled in?
    // This part is treated in the normal page.
    // I put all boxes and their values in textstring

    for (i=0;i<1;i++)
    {
    box = document.forms[0].elements[i];
    if (!box.name)
    {
    alert('You haven\'t filled in ' + box.value + '!');
    box.focus()
    return;
    }
    textstring +='' + box.value + '';
    }


    // Write textstring to the textarea.

    document.forms[0].output.value = textstring;
    }
    // -->
    </SCRIPT>

    </HEAD>
    <BODY>
    <form name="example" onsubmit="checkit(); return false">
    <center>
    <table cellspacing=0 border=0 width=80% class="form">
    <tr>
    <TD colspan="2"><textarea rows="4" name="Sometext" value='0' cols="104"></textarea></TD>
    </tr>
    <TR>
    <TD colspan="2"><TEXTAREA COLS=104 ROWS=8 NAME=output WRAP=virtual>When you hit 'Submit' the user input will be written to this textarea</TEXTAREA></TD>
    <TR><TD COLSPAN=2 ALIGN=center><INPUT TYPE=submit VALUE="Submit form"><INPUT TYPE=reset></TD></TR>
    <TR><TD COLSPAN=2 ALIGN=center>&nbsp;</TD></TR>
    </TABLE>
    </CENTER>
    </FORM>
    </BODY>
    </HTML>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •