How to set the text of a textarea tag?

Discussion in 'JavaScript' started by Betty_S, Mar 18, 2007.

  1. #1
    Hi,

    Believe you me, I triad to find the answer myself because its really shouldn’t be a big deal but I just couldn’t clean the text of the my textarea tag.
    I triad
    
    document.formName.textareaName.value=’’;
    document.getElementById(“textareaId”).value=””;
    
    Code (markup):
    But it failed
    What to do?
    Thanks.
     
    Betty_S, Mar 18, 2007 IP
  2. jmort732

    jmort732 Peon

    Messages:
    543
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please don't take this the wrong way, but do you have a class set for it in your CSS?

    If you do, I think the cascade will overwrite the javascript setting the value to "empty".

    Morty
     
    jmort732, Mar 18, 2007 IP
  3. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #3
    There is no problem with your script. Check whether you have the readonly attribute set in the html code. if that too doesn't work, try alerting the textarea object to make sure that the element exists or not.
    alert(document.formName.textareaName);
    Code (markup):
    If you get undefined, then the object doesn't exist. If you get no alert box, then there is some problem with the code prior to it.

    If you want further help, post the entire code or the link to the page here.
     
    Aragorn, Mar 18, 2007 IP
  4. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Try this:

    if ( document.getElementById(“textareaId”).firstChild ) {
       document.getElementById(“textareaId”).firstChild.data = "";
    }
    Code (markup):
     
    phper, Mar 18, 2007 IP
  5. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #5
    phper seems to be on the right track (I think that's fireFox support no?). Also you may consider:

    <textarea id="textareaId">yadayada</textarea>

    ...
    ...
    ...
    document.getElementById('textareaId").innerText = 'nothing'; OR
    document.getElementById('textareaId").innerHTML = 'nothing';
     
    datropics, Mar 19, 2007 IP