Bojak Posted September 18, 2013 Share Posted September 18, 2013 <!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? Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/ Share on other sites More sharing options...
Irate Posted September 18, 2013 Share Posted September 18, 2013 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"; Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450168 Share on other sites More sharing options...
KubeR Posted September 18, 2013 Share Posted September 18, 2013 (edited) getElementByIdShould start with a lowercaseed letter and the .hide function doesn't accept any arguements.Nevertheless,it is a jQuery function. Â EDIT: looks like somebody else answered it before me . Edited September 18, 2013 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450169 Share on other sites More sharing options...
Bojak Posted September 18, 2013 Author Share Posted September 18, 2013 <!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? Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450170 Share on other sites More sharing options...
Bojak Posted September 18, 2013 Author Share Posted September 18, 2013 it hides it when i click the corner i think a button would be better but im not sure on how to go about doing that. Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450173 Share on other sites More sharing options...
KubeR Posted September 19, 2013 Share Posted September 19, 2013 it hides it when i click the corner i think a button would be better but im not sure on how to go about doing that. well,if you're still interested in a button,then take a look at this page : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450177 Share on other sites More sharing options...
Bojak Posted September 19, 2013 Author Share Posted September 19, 2013 <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? Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450179 Share on other sites More sharing options...
Bojak Posted September 19, 2013 Author Share Posted September 19, 2013 that only makes the entire box hidden when you click it. Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450181 Share on other sites More sharing options...
Irate Posted September 19, 2013 Share Posted September 19, 2013 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). Quote Link to comment https://forums.phpfreaks.com/topic/282264-javascript-hide-textarea/#findComment-1450195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.