Results 1 to 4 of 4

Thread: Generate Text

  1. #1
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Question Generate Text

    All right, Could use some help here... I need to make a script that will alow me to generate text inside of a <textarea>. For example:

    HTML Code:
    <select id="select">
    <option>option 1</option>
    <option>option 2</option>
    </select>
    <br><br><br>
    <input type="button" value="Generate"><br>
    <textarea cols=10 rows=5></textarea>

    When you click 'Generate', text specified by the value of selct menu is placed within the <textarea>. Anyone have an Idea???
    Last edited by kaos; 08-10-2009 at 01:47 AM.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,793
    Thanks
    2
    Thanked 418 Times in 412 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Text(from,to){
     if (document.getElementById(from).value) document.getElementById(to).value=document.getElementById(from).value;
    }
    /*]]>*/
    </script></head>
    
    <body>
    <select id="select">
    <option value="Text 1" >option 1</option>
    <option value="Text 2">option 2</option>
    </select>
    <br><br><br>
    <input type="button" value="Generate" onclick="Text('select','ta')"><br>
    <textarea id="ta" cols=10 rows=5></textarea>
    </body>
    
    </html>
    or

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    var Ary=[];
    Ary[0]='Text One';
    Ary[1]='Text Two';
    
    function Text(from,to,ary){
     var index=document.getElementById(from).selectedIndex;
     if (ary[index]) document.getElementById(to).value=ary[index];
    }
    /*]]>*/
    </script></head>
    
    <body>
    <select id="select">
    <option>option 1</option>
    <option>option 2</option>
    </select>
    <br><br><br>
    <input type="button" value="Generate" onclick="Text('select','ta',Ary)"><br>
    <textarea id="ta" cols=10 rows=5></textarea>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Lightbulb Thanks

    Thanks, but is it possible to hold the select option's values that will be placed in the textarea in an external file(s)?

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,793
    Thanks
    2
    Thanked 418 Times in 412 Posts

    Default

    simplest would be to define an array in an external javascript file, this could also be used to define the select list options.
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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
  •