Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript: how to set content of a text area

  • 19-04-2007 04:07PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 26 ast


    mytextarea.value = "new text";
    

    Otherwise check that getElementById() is finding your textarea


  • Registered Users, Registered Users 2 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