ltrem Posted September 17, 2009 Share Posted September 17, 2009 Hey guys, I just CAN'T get the text from a <textarea> with the getElementById... the only way I can do it is by putting my <textarea> in a <form> and doing something like document.form1.textarea1.value why is this not working? --> document.getElementById('textarea1').value Thanks Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2009 Share Posted September 17, 2009 It works for me: <html> <head> <title>Blah</title> <script type="text/javascript"> window.onload = function(){ var oTextarea = document.getElementById('myText'); alert(oTextarea.value); } </script> </head> <body> <textarea id="myText">Hello world</textarea> </body> </html> How are you filling the textarea? Quote Link to comment Share on other sites More sharing options...
ltrem Posted September 17, 2009 Author Share Posted September 17, 2009 I have this when the page load <textarea name="commentaire" id="commentaire" rows="3" cols="54"></textarea> Then I type some text, click on a button that execute a alert and the alert doesn't display anything... if I put this otherwise <textarea name="commentaire" id="commentaire" rows="3" cols="54">TEST</textarea> and click my button, the alert display TEST... ... Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2009 Share Posted September 17, 2009 The following works for me in IE8 and FF 3.5: <html> <head> <title>Blah</title> <script type="text/javascript"> window.onload = function(){ var oTextarea = document.getElementById('myText'); var oButton = document.getElementById('myButton'); oButton.onclick = function(){ alert(oTextarea.value); } } </script> </head> <body> <textarea id="myText"></textarea> <button id="myButton">Click</button> </body> </html> Quote Link to comment Share on other sites More sharing options...
ltrem Posted September 17, 2009 Author Share Posted September 17, 2009 For fun I tried to copy past your textarea and javascript code and it worked... I then tried my code again.. didn't work... I then changed the id="commentaire" to id="whatever" and it worked..... WTF :wtf: It seems that the code just don't like the id "commentaire".... WTF !???? I searched all my code and I have NO other place with "commentaire"........ Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 17, 2009 Share Posted September 17, 2009 For fun I tried to copy past your textarea and javascript code and it worked... I then tried my code again.. didn't work... I then changed the id="commentaire" to id="whatever" and it worked..... WTF :wtf: It seems that the code just don't like the id "commentaire".... WTF !???? I searched all my code and I have NO other place with "commentaire"........ I'm just going to say that it most likely is a typo... however, if you post your code, it usually helps to have a second set of eyes. :-) Quote Link to comment Share on other sites More sharing options...
ltrem Posted September 17, 2009 Author Share Posted September 17, 2009 I just tried again with "commentaire" as an ID and still didn't work... No typo error 100% sure... Even if I look in the source code I don't see ANY "commentaire" in all the damn page!!! weird.... Quote Link to comment 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.