Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript: how to set content of a text area

Options
  • 19-04-2007 5:07pm
    #1
    Registered Users Posts: 2,364 ✭✭✭


    Can some kind soul tell me how I can set the text inside a 'textarea' using javascript. I want to do this so I can use AJAX to change the text.

    I have this:
    var mytextarea= document.getElementById("mytextarea");
    mytextarea.setContent("new text");
    
    I saw the function getContent() somewhere on the net, but is it just a function somebody wrote and not part of javascript? It doesn't work anyway.


Comments

  • Closed Accounts Posts: 884 ✭✭✭NutJob


    is the textarea a div textbox or some micosoft asp thingy?

    try should work anyway


    var mytextarea= document.getElementById("mytextarea");
    mytextarea.setContent("new text");
    Also because im in a good mood today and you posted some code heres a crash cource in javascript for the lazy(like me).:)

    http://www.youtube.com/watch?v=UJBkQhA2CRA
    can also be found at the chays computer club web site in better quality.


  • Registered Users Posts: 2,364 ✭✭✭Mr. Flibble


    NutJob wrote:
    is the textarea a div textbox or some micosoft asp thingy?

    try should work anyway


    var mytextarea= document.getElementById("mytextarea");
    mytextarea.setContent("new text");
    Also because im in a good mood today and you posted some code heres a crash cource in javascript for the lazy(like me).:)

    http://www.youtube.com/watch?v=UJBkQhA2CRA
    can also be found at the chays computer club web site in better quality.

    This is the code for the textbox
    <FORM NAME="myform">
    <td><TEXTAREA NAME="mytextbox" COLS=40 ROWS=19>stuff</TEXTAREA>
    </FORM>
    
    Are you saying the setContent() function should work?


    ps. i think you have the wrong youtube link.


  • Registered Users Posts: 26 ast


    mytextarea.value = "new text";
    

    Otherwise check that getElementById() is finding your textarea


  • Registered Users Posts: 2,364 ✭✭✭Mr. Flibble


    ast wrote:
    mytextarea.value = "new text";
    

    Otherwise check that getElementById() is finding your textarea

    Cool. That was the problem. Adding "id=myid" in the html textarea code fixed it. Thanks.


Advertisement