www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: setting text in a textarea

  1. #1
    Join Date
    Sep 2003
    Posts
    651

    setting text in a textarea

    i'm trying to set text in a textarea but it's not working.
    what am i doing wrong

    Code:
    var emailbodyt='test';
    alert(emailbodyt);
    var txtArea = document.getElementById('emailbody');
    txtArea.value = emailbodyt;
    it's not replacing the text area with the emailbodyt text.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    It shouldn't be a problem if the script is run after the document has loaded
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    
    <script type="text/javascript">
    window.onload=function() {
    var emailbodyt='test';
    alert(emailbodyt);
    var txtArea = document.getElementById('emailbody');
    txtArea.value = emailbodyt;
    };
    </script>
    
    <style type="text/css">
    * {margin:0;padding:0;}
    </style>
    
    </head>
    <body>
    <textarea id="emailbody" rows="10" cols="10">
    </textarea>
    </body>
    </html>

  3. #3
    Join Date
    Sep 2003
    Posts
    651
    i'm running it onchange of a text box in my form
    here is my full code - what is wrong?

    Code:
    
    function semail(statusid){
    
    if(statusid==3){
    
    amount=document.getElementById('amount').value;
    //alert("here");
    var emailbodyt=document.getElementById('emailbodyt').innerHTML;
    alert(emailbodyt);
    var txtArea = document.getElementById('emailbody');
    txtArea.value = emailbodyt;
    
     
    }
    
    
    }

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    var emailbodyt=document.getElementById('emailbodyt').innerHTML;
    What is the innerHTML?

  5. #5
    Join Date
    Jun 2010
    Posts
    3

    typo?

    Quote Originally Posted by esthera View Post
    i'm trying to set text in a textarea but it's not working.
    what am i doing wrong

    Code:
    var emailbodyt='test';
    alert(emailbodyt);
    var txtArea = document.getElementById('emailbody');
    txtArea.value = emailbodyt;
    it's not replacing the text area with the emailbodyt text.
    the getElementByIt says 'emailbody', but your other variables say 'emailbodyt'. Is that on purpose or is that your typo?

  6. #6
    Join Date
    Sep 2003
    Posts
    651
    no emailbodyt is not a typo

    var emailbodyt=document.getElementById('emailbodyt').innerHTML;
    this is html that I want to take and change and then put into the textarea

  7. #7
    Join Date
    Sep 2003
    Posts
    651
    I found the problem

    my textarea is using javascript to format it as a wyswyg
    Code:
        <script language="javascript1.2">
    var config = new Object();    // create new config object
    config.width = "500px";
    config.height = "200px";
    config.bodyStyle = 'background-color: white; font-family: "Verdana"; font-size: x-small;';
    config.debug = 0;
    config.toolbar = [
        ['bold','italic','underline','strikethrough','subscript','superscript','justifyleft','justifycenter','justifyright','OrderedList','UnOrderedList','Outdent','Indent'],
     
      
    ];
    editor_generate('emailbody',config);
                 </script>
    anyway to get this to work together with my javascript allowing me to change the text? or can I get this javascript to pull into it the text from the div emailbodyt ?

  8. #8
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You can't put html in a textarea. RTEs use an iframe to style the content.
    Follow this post: http://www.webdeveloper.com/forum/sh...d.php?t=231226

  9. #9
    Join Date
    Sep 2003
    Posts
    651
    so you are saying (based on that thread) if I switch to tinymce editor then it would work?

  10. #10
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    What are you ultimately trying to achieve?

  11. #11
    Join Date
    Sep 2003
    Posts
    651
    I want to be able to chagne text in my textarea and fill in fields from my form (and as they change the values they should change in my textarea)

  12. #12
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Do you have a working form example?

  13. #13
    Join Date
    Sep 2003
    Posts
    651
    http://www.awebfor you.com/t/test.html

  14. #14
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <input name="amount" value="250" onchange="this.form.emailbody.value+=this.value;" type="text">

  15. #15
    Join Date
    Sep 2003
    Posts
    651
    but i need to just repalce the words from the hidden text field and replace that to thte textarea so this won't really help (plus it's doing the same thing so I doubt it will work)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles