Jump to content

javascript hide textarea


Bojak

Recommended Posts

	

     <!DOCTYPE html>
    <html>
    <head>
    <script>
    function HideComment()
    {
    document.GetElementById("comments").hide("textarea")
    }
    </script>
    </head>
     
    <body>
    <textarea name="" cols="" rows="" id="comments" onClick="">leave comment</textarea>
    </body>
    </html>


i am trying to get the text area to hide when i click a button. this is what i have but doesnt seem to work. can someone help me?

Link to comment
Share on other sites

First of all, JavaScript is case-sensitive.

.GetElementById is not the same as .getElementById, and there is no DOM method named .hide, either.

You can change CSS styles with the .style property, for example, this hides the first textarea in the document: document.getElementsByTagName("textarea")[0].style.display = "none";

Link to comment
Share on other sites

 <!DOCTYPE html>
<html>
<head>
<script>
function HideComment()
{
document.getElementsByTagName("textarea")[0].style.display = "none"; 
}
</script>
</head>

<body>
<textarea name="" cols="" rows="" id="comments" onClick="HideComment()">leave comment</textarea> 
</body>
</html>

so this should hide it when its clicked? how would i make a button hide it instead?

Link to comment
Share on other sites

<head>
<script>
function HideComment()
{
document.getElementsByTagName("textarea")[0].style.display = "none"; 
}
</script>
</head>

<body>
<textarea name="" cols="" rows="" id="comments">leave comment</textarea> 
<button name="hide" onClick="HideComment()"> </button>
</body>
</html>

like this?

Link to comment
Share on other sites

You want to clear the textarea value only?

Use the .value property to get the value from the textarea, save it into a variable and then empty the .value property, then do with the variable whatever you need (sending it to a PHP script or whatever else you need).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.