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
https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/
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";

 <!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?

<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?

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.